CodeIgniter Forums
Query bindings in CI 3 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Query bindings in CI 3 (/showthread.php?tid=75001)



Query bindings in CI 3 - Danny - 12-05-2019

Hi!

I just updated from CI 2.x to CI 3.1.11.
Everything works fine except :

Now the query function checks that the number of supplied parameters matches the number of bind marker present in the sql query.

This change was not mentioned in the upgrade guide.

How to get rid of that check. 

I have some conditional queries that don't work anymore due to that parameter check.

ex : SELECT ?, ? FROM table; 
should work even if too many parameters supplied 
$param = ['a','b','c']; => 'c' is just discarded.

THANK YOU!


RE: Query bindings in CI 3 - muuucho - 12-06-2019

(12-05-2019, 09:04 AM)Danny Wrote: Hi!

I just updated from CI 2.x to CI 3.1.11.
Everything works fine except :

Now the query function checks that the number of supplied parameters matches the number of bind marker present in the sql query.

This change was not mentioned in the upgrade guide.

How to get rid of that check. 

I have some conditional queries that don't work anymore due to that parameter check.

ex : SELECT ?, ? FROM table; 
should work even if too many parameters supplied 
$param = ['a','b','c']; => 'c' is just discarded.

THANK YOU!
Prepared statements are usually not used for column names.
Also, if you have 3 elements in $param, you should have 3 question marks in your query.

An example of a prepared statement:
Code:
"INSERT INTO users (firstname, lastname, email) VALUES (?, ?, ?)"