Replies: 2 comments 2 replies
-
The keys you specified in the array doesn't matter because the query builder is only interested in the values: framework/src/Illuminate/Database/Query/Builder.php Lines 3262 to 3266 in 8e2d727 Meaning you should pass a simple array with as many values as your query has parameters. The query builder will walk the query query and insert item by item. And because the name of the parameter is irrelevant you can even shorten the query by using Job::whereRaw(
'IF (? IS NOT NULL AND ? IS NOT NULL, duedate BETWEEN ? AND ?, 1)',
[ $duedatefrom, $duedateto, $duedatefrom, $duedateto ]
)->get(); |
Beta Was this translation helpful? Give feedback.
-
According to this stackoverflow answers you can't use the same parameter name more than once in a prepared statement, unless emulation mode is on. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a question, as I have a query like this
I have two variables, duedatefrom and duedateto, and I use them in the query two times, then I get the error "SQLSTATE[HY093]: Invalid parameter number".
So what is the correct way to use a variable several times in the query, without having to duplicate the parameters?
Also, using with postgresql, that same query works perfectly and I can use :duedatefrom and :duedateto as many times as I want.
Beta Was this translation helpful? Give feedback.
All reactions