PHP变量适应表达式中的sql

时间:2017-01-29 04:49:54

标签: php sql-server expression

SELECT * FROM suppliers WHERE supplier_name IN ('Microsoft', 'Oracle', 'Flowers Foods')

IN内部表达式中,我想声明PHP变量。但我的变量没有单引号。

这是我的php变量$Myvariable = 'Microsoft,Oracle,Flowers Foods';

1 个答案:

答案 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