CodeIgniter Forums
Stupid question about query bindings - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Stupid question about query bindings (/showthread.php?tid=2802)



Stupid question about query bindings - El Forum - 08-24-2007

[eluser]Martín M.[/eluser]
Hi.

I'm using query bindings to gather data from a database. I have a really simple query:
Code:
$query = $this->db->query("SELECT * FROM table WHERE name LIKE '%?%'", $term);

Of course this doesn't work, since generates this query (note the quotes surrounding the search term):
Code:
SELECT * FROM table WHERE name LIKE '%'yaddayadda'%'

I fixed it this way:
Code:
$query = $this->db->query("SELECT * FROM table WHERE nombre LIKE ?", '%' . $term . '%')

It works, but it feels like it's not a very brilliant thing. Is this the way to go or I'm being really stupid?


Stupid question about query bindings - El Forum - 08-24-2007

[eluser]chobo[/eluser]
The fix looks much better then your first attempt.