1

I am a ZF beginner and I can not find answer by googling. I have something like that:

$query->where('sc.year BETWEEN ? AND ?', array($startYear, $endYear));

As you can see I try to pass 2 parameters as array (see https://stackoverflow.com/a/3305202/2995868). But it does not work. I have performed a simple test:

$query->where("sc.year BETWEEN ? AND ?",array(1,2))
->where("sc.week BETWEEN IF(year = ?, ?, 1) AND IF(year = ?, ?,53)",array(3,4,5,6));

What I expect to see in raw SQL:

...WHERE (sc.year BETWEEN 1 AND 2) AND (sc.week BETWEEN IF(year = 3, 4, 1) AND IF(year = 5, 6, 53))

What I really see:

...WHERE (sc.year BETWEEN 1, 2 AND 1, 2) AND (sc.week BETWEEN IF(year = 3, 4, 5, 6, 3, 4, 5, 6, 1) AND IF(year = 3, 4, 5, 6, 3, 4, 5, 6, 53)) 

So ZF just converts array to string and inserts it like single parameter.

Also I try something in native PHP style:

$query->where('sc.year BETWEEN ? AND ?', $startYear, $endYear);

It still not works.

I know, that I can use string functions like sprintf, but I want to understand how to pass more than one parameter via Zend_Db in right way.

Community
  • 1
  • 1
Hovsep
  • 377
  • 1
  • 4
  • 12
  • You can try `$query->where("sc.year BETWEEN $startYear AND $endYear");` – Muhammad Zeeshan Dec 30 '13 at 08:44
  • 1
    @MuhammadZeeshan thanks! It is really beautiful solution! But I think, parameters passed that way will not be properly quoted into statement. Anyway it will work for me,because I use simple integer parameters. – Hovsep Dec 30 '13 at 10:30
  • 2
    Your first code sample is the correct way. Could you give more info about why this doesn't work? If you `echo $query` to output the SQL, what to you get? – Tim Fountain Dec 30 '13 at 20:26
  • @TimFountain I have edited question, please see above. – Hovsep Jan 03 '14 at 06:45
  • Based on the output you're getting, it seems like `$startYear` and `$endYear` are already arrays. Are you sure they're just integers? – Tim Fountain Jan 03 '14 at 09:44
  • @TimFountain $startYear and $endYear are integer variables. – Hovsep Jan 03 '14 at 09:49

0 Answers0