Vayas
Vayas

Reputation: 107

Array in the parameter when creating PDO query

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

Upvotes: 3

Views: 128

Answers (2)

Vayas
Vayas

Reputation: 107

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

Upvotes: 0

Kush
Kush

Reputation: 1522

<?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)
);
?>

Upvotes: 3

Related Questions