SELECT * FROM suppliers WHERE supplier_name IN ('Microsoft', 'Oracle', 'Flowers Foods')
在IN
内部表达式中,我想声明PHP变量。但我的变量没有单引号。
这是我的php变量$Myvariable = 'Microsoft,Oracle,Flowers Foods';
答案 0 :(得分:3)
你可以这样做: -
<?php
$Myvariable = 'Microsoft,Oracle,Flowers Foods';
$Myvariable = "'".implode("','",explode(',',$Myvariable))."'";
echo $Myvariable;
echo PHP_EOL;
echo "SELECT * FROM suppliers WHERE supplier_name IN ($Myvariable) ";
输出: - https://eval.in/726208