如何在mySQL中的REGEX中添加PHP变量

时间:2013-12-11 12:34:19

标签: php mysql sql

如何在mySQL中的REGEX中添加PHP变量

我的代码就像这样

SELECT count(product_id) as totalCount FROM ref_products WHERE misc REGEXP '(.*\"level_id\":\'".$course_level_id."'\.*)'     

3 个答案:

答案 0 :(得分:1)

假设您使用双引号字符串(“):

$sql = "SELECT count(product_id) as totalCount FROM ref_products WHERE misc REGEXP '(.*\"level_id\":\'".$course_level_id."'.*)'";

假设您使用单引号字符串('):

$sql = 'SELECT count(product_id) as totalCount FROM ref_products WHERE misc REGEXP \'(.*\"level_id\":'.$course_level_id.'.*)\'';

答案 1 :(得分:1)

感谢所有人的时间和时间。努力。这是我找到的正确答案。请检查

SELECT count(product_id) as totalCount FROM ref_products WHERE misc REGEXP '(.*\"level_id\":$course_level_id.*)'

答案 2 :(得分:0)

SELECT count(product_id) as totalCount FROM ref_products WHERE misc REGEXP '(.*"level_id":"'.$course_level_id.'".*)'