是否可以在mysql查询中传递php整数变量?
喜欢$g = 44 ;
$sql="
SELECT
idtransactiondetails,
idtransactionmaster,
T.idacledger,
acledgername,
transactionamount,
chequeno
from transactiondetails T,
acledger L
where
T.idacledger=L.idacledger
and idtransactionmaster=int()$g";
但如果$g
无效。
答案 0 :(得分:0)
$sql="SELECT idtransactiondetails,idtransactionmaster,T.idacledger,acledgername,transactionamount,chequeno from transactiondetails T,acledger L where T.idacledger=L.idacledger and idtransactionmaster="`.$g;`
答案 1 :(得分:0)
试试这个
$sql="SELECT idtransactiondetails,idtransactionmaster,T.idacledger,acledgername,transactionamount,chequeno from transactiondetails T,acledger L where T.idacledger=L.idacledger and idtransactionmaster=$g";
答案 2 :(得分:0)
Concatenate字符串:
$sql = "SELECT idtransactiondetails, idtransactionmaster, T.idacledger, acledgername, transactionamount, chequeno
FROM transactiondetails T, acledger L
WHERE T.idacledger = L.idacledger
AND idtransactionmaster=" . (int) $g. ";";
答案 3 :(得分:0)
不需要在Query中使用int,
$sql="SELECT idtransactiondetails,idtransactionmaster,T.idacledger,acledgername,transactionamount,chequeno from transactiondetails T,acledger L where T.idacledger=L.idacledger and idtransactionmaster= $g ";
答案 4 :(得分:0)
如果你试图避免sql注入,那么确认你的变量包含整数值。所有
$g = "50'a+_)(*&^%$#@!";
$integer = intval($g); // 50
$sql = "SELECT idtransactiondetails,idtransactionmaster,T.idacledger,acledgername,transactionamount,chequeno from transactiondetails T,acledger L where T.idacledger=L.idacledger and idtransactionmaster = '$integer'";