问题
Can I use a few lines in the parameter
Example
SELECT id, city_id FROM an_objects WHERE city_id IN (:arrCity)
(:arrCity) (1,2,3,4,5,6)
But now I have done like this
SELECT id, city_id FROM an_objects WHERE city_id IN (:1p, :2p, :3p, ...... :100p)
And it's very bad
回答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)
);
?>
回答2:
And how in that case to be a query?
WHERE city_id IN (:1p, :2p, :3p, ...... :100p)
In the query 100 parameters
In this method, for example, we have only 5 parameters
private function PDOBindArray(&$poStatement, &$paArray){
foreach ($paArray as $k=>$v) {
@$poStatement->bindValue($k, $v[0], $v[1]);
}
}
来源:https://stackoverflow.com/questions/13962266/array-in-the-parameter-when-creating-pdo-query