This question has already been answered:
- Competent protection against SQL-Injection 3 responses
- Protection against SQL injections in php 1 answer
Tell me the functions for protection) here’s the request itself) All parameters to the method are transferred from the query string.
$catSlug = Slug категории $page = страница пагинации public static function catProductList($catSlug, $page = 1) { if ($catSlug) { $page = intval($page); $offset = ($page - 1) * self::SHOW_BY_DEFAULT; $db = Db::getConnection(); $catProd = array(); $result = $db->query("SELECT * FROM product WHERE status='1' AND category_sl='$catSlug' ORDER BY id DESC LIMIT ".self::SHOW_BY_DEFAULT." OFFSET ".$offset); $i = 0; while($row = $result->fetch()){ $catProd[$i]['id'] = $row['id']; $catProd[$i]['name'] = $row['name']; $catProd[$i]['price'] = $row['price']; $catProd[$i]['image'] = $row['image']; $catProd[$i]['is_new'] = $row['is_new']; $catProd[$i]['slug'] = $row['slug']; $i++; } return $catProd; } }
mysqli_real_escape_string($db, query)for PDO there are new queries, and so on. - Evgeny Ivanov