[Solar-talk] multiple SQL predicates
Paul M Jones
pmjones at solarphp.com
Thu Dec 6 11:20:44 CST 2007
On 06 Dec 2007, at 12:06, Cruz, Darwin wrote:
> I'm trying to query the database using a SQL query with multiple
> predicate clauses and i'm trying to figure out the best way to do
> that:
>
> select * from customer where first_name = 'jim' and last_name =
> 'smith'
> and zipcode between 07710 and 07734;
>
> I've tried quilding an array to pass to the fetchAll() method but i'm
> not getting anything:
>
> $options = array(
> 'where' => array(
> 'first_name = jim',
> 'last_name = smith',
> 'zipcode between 07710 and 07734',
>
> ),
>
> );
>
> $result = $myModel->fetchAll($options);
>
>
> I've also tried building a Pdo statement as well with no luck:
>
>
>
> $pdoStatement = $sql->query('select * from customer
> where first_name = 'jim' and last_name = 'smith' and zipcode between
> 07710 and 07734');
> $result = $myModel->fetchPdo($pdoStatement);
Well, that last one won't work for sure -- fetchPdo() doesn't take a
PDOStatement, it returns one.
What happens if you issue this?
$cmd = "select * from customer
where first_name = :first_name
and last_name = :last_name
and zipcode between :zip1 and :zip2";
$all = $sql->fetchAll($cmd, array(
'first_name' => 'jim',
'last_name' => 'smith',
'zip1' => '07710',
'zip2' => '07734'
));
Solar::dump($all);
-- pmj
More information about the Solar-talk
mailing list