2017-12-08 14:59
浏览 80

使用php数组作为Postgres IN子句的参数

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).")"; 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题