catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

customized query issue! #693

Closed imrooster closed 6 years ago

imrooster commented 6 years ago

hi @catfan

some issue about customized query

$area=["Canada", "America"];
$sql="SELECT * FROM course WHERE location IN (:area)";
$database->debug()->query($sql, [
    ":area"=>$area
])

result SELECT * FROM "course" WHERE "location" IN ('Canada,America')

$area not treated as array, but only string!

BUT if i don't use customized query, it works correctly

$area=["Canada", "America"];
$database->debug()->select("course", 
    "*", [
    "location" => $area
]);

result SELECT * FROM "course" WHERE "location" IN ('Canada','America')

anyone can help me to fix this problem? thanks a million!!

catfan commented 6 years ago

Because the PDO bindValue do not support array value in native. You can not just assign array for prepared statement. http://php.net/manual/en/pdostatement.bindvalue.php

The best way is just using Medoo function for this case as possible. It will convert value as correct type for the IN statement.