so just to give you a idea i moved over from mysqli (none oop method) to PDO and all my queries work 100% except for this one little bugger.
$query = $link->prepare("SELECT n1.id,n1.category_id,(SELECT name FROM food_categories WHERE id=n1.category_id) AS category_name FROM foods AS n1 WHERE n1.name=:dish"); $query->execute(array(':dish'=>$dish));
What i have tired
First i checked my query in PHPMyAdmin to see if it works and it does if i put single quotes around the :dish placeholder (with the actual food’s name), without the quotes i get a error like i would normally get which said “Unknown column ‘food1’ in ‘where clause’”
So i fired up the Googler and found out that there is a quote function for PDO but that is not for prepared statements because prepared statements auto quotes placeholders for you.
Then i moved on to check if there is any errors in the execution itself and the code i got back was the 00000, which i understands means that there is no problem and the query didn’t have a error.
I also used the:
which both of them didn’t work, so i am sitting here and wondering if PDO is not quoting the placeholder for some reason because that is the only thing i have seen which caused there to be no result.
I have also checked the
$dish variable and there is nothing wrong with it, plus i replaced it with
'food1' to see if it’s that but it still does not work.
Thank you for reading.