数组值变为“SELECT ....”

时间:2017-06-16 15:31:52

标签: mysql arrays escaping concatenation quotes

我有一个查询变量,我想知道LIKE'“。$ producto ['product_reference']中是否有任何替代引号。”'

$producto_color = Db::getInstance()->ExecuteS(
                    "SELECT `name` 
                    FROM `jd_attribute_lang` 
                    WHERE `id_attribute` 
                    IN (
                        SELECT `id_attribute` 
                        FROM `jd_product_attribute_combination` 
                        WHERE `id_product_attribute` 
                        IN (
                            SELECT `id_product_attribute` 
                            FROM `jd_product_attribute` 
                            WHERE `reference`
                            LIKE '".$producto['product_reference']."'
                            )
                        )
                    AND `id_attribute` 
                    IN(
                        SELECT `id_attribute`
                        FROM `jd_attribute` 
                        WHERE `id_attribute_group` LIKE 2
                        OR `id_attribute_group` LIKE 5
                        OR `id_attribute_group` LIKE 9
                        OR `id_attribute_group` LIKE 10
                        OR `id_attribute_group` LIKE 11
                        OR `id_attribute_group` LIKE 12
                        OR `id_attribute_group` LIKE 16
                        OR `id_attribute_group` LIKE 19
                        OR `id_attribute_group` LIKE 20
                        ) 
                    AND `id_lang` = $id_language"
                );

感谢!!!

1 个答案:

答案 0 :(得分:0)

在php中编写它的那种风格的替代方案就是这样一行:

LIKE #{$producto['product_reference']}

这种风格不会让你结束我在输入长PHP字符串时发现更方便的引号。你必须结束引号的点符号在较短的字符串中偶尔会更方便,但在更长的字符串中,我更喜欢这种插入变量的方式。