[Solar-talk] multiple SQL predicates

Kilbride, James P. James.Kilbride at gd-ais.com
Thu Dec 6 11:46:00 CST 2007


Paul,

what's the problem with the first method using the models? Also how do
you define difference between and and or statements when fetching
models? I noticed with the magic selects you can do and, anyway to do an
or statement? I'm trying to get folks away from writing the sql because
then they get bound to specific conventions of the different databases.

James Kilbride 

-----Original Message-----
From: solar-talk-bounces at lists.solarphp.com
[mailto:solar-talk-bounces at lists.solarphp.com] On Behalf Of Paul M Jones
Sent: Thursday, December 06, 2007 12:21 PM
To: solar-talk at lists.solarphp.com
Subject: Re: [Solar-talk] multiple SQL predicates


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
_______________________________________________
Solar-talk mailing list
Solar-talk at lists.solarphp.com
http://mailman-mail3.webfaction.com/listinfo/solar-talk



More information about the Solar-talk mailing list