Например:
$ parent_category_name = Мужская одежда
Рассмотрим здесь SQL-запрос
$sql_category_name = "SELECT c.*, cd.name, cd.category_id as iid FROM ". DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) WHERE cd.name = '" . $this->db->escape($parent_category_name) . "' AND c.parent_id =0 ";
Ошибка:
Static analysis:
1 errors were found during analysis.
Ending quote ' was expected. (near "" at position 198)
SQL query: Documentation
SELECT c.*, cd.name, cd.category_id as iid FROM oc_category c LEFT JOIN oc_category_description cd ON (c.category_id = cd.category_id) WHERE cd.name = 'Men's Clothing' AND c.parent_id =0 LIMIT 0, 25
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Clothing' AND c.parent_id =0 LIMIT 0, 25' at line 1
Попробуйте реализовать:
$this->db->escape($parent_category_name)
Вышеуказанный метод работает на платформе OpenCart. Найдите свой фреймворк и внедрите ИЛИ
mysql_real_escape_string()
в ядре PHP
Это станет мужской одеждой, т.е. в моем случае
$sql_category_name = "SELECT c.*, cd.name, cd.category_id as iid FROM ". DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) WHERE cd.name = '" . $this->db->escape($parent_category_name) . "' AND c.parent_id =0 ";
Таким образом, вы получите четкую картину запроса, реализовав escape () как
SELECT c.*, cd.name, cd.category_id as iid FROM oc_category c LEFT JOIN oc_category_description cd ON (c.category_id = cd.category_id) WHERE cd.name = 'Men\'s Clothing' AND c.parent_id =0