Welcome Guest, Not a member yet? Register   Sign In
Stupid question about query bindings
#1

[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?
#2

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




Theme © iAndrew 2016 - Forum software by © MyBB