3

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
  • 1
    You can construct the parameter list in the prepared statement dynamically, using a loop. Commented Dec 19, 2012 at 22:31

2 Answers 2

3
<?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)
);
?>
Sign up to request clarification or add additional context in comments.

Comments

0

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]);
    }      
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.