I am trying to bind a PHP array as argument for a SQL stmt. I am using auraSQL extended PDO so it looks like this:
$php_array = ['first', 'second', 'third']
$db->fetchColumn("SELECT * FROM my_table WHERE column IN (:php_array), ['php_array' => $php_array])"
Is there a way to do that? I cannot find out how. I tried to append the $php_array
as string separated with commas and wrapped in quotes but that doesn't work.
EDIT: Solution was to use AuraSql function quote
like so:
$db->fetchColumn("SELECT * FROM my_table WHERE column IN (".$db->quote($php_array).")";
Take a look at the Aura.Sql documentation for quote()
, here: https://github.com/auraphp/Aura.Sql/blob/3.x/docs/getting-started.md#array-quoting
The SQL IN
clause requires a comma-delimited list of values. The Aura.Sql quote()
method appears to generate that for you.
You should consider using perform
method.
https://github.com/auraphp/Aura.Sql/blob/3.x/docs/getting-started.md#the-perform-method