一尘不染

创建PDO查询时参数中的数组

sql

我可以在参数
示例中使用几行吗

SELECT id, city_id FROM an_objects WHERE city_id IN (:arrCity)

(:arrCity)(1,2,3,4,5,6)

但是现在我已经完成了

SELECT id, city_id FROM an_objects WHERE city_id IN (:1p, :2p, :3p, ...... :100p)

而且非常糟糕


阅读 255

收藏
2021-03-08

共1个答案

一尘不染

<?php

private function PDOBindArray(&$poStatement, &$paArray){ 
    foreach ($paArray as $k=>$v) {
        @$poStatement->bindValue($k, $v[0], $v[1]);
    }      
}

// the array structure should now look something like this

$inputArray = array(
    ':arrcity' => array($email, PDO::PARAM_STR), 
    ':another_variable' => array($pass, PDO::PARAM_INT)
);
?>
2021-03-08