Converted PHP query to PDO and now getting no results
Posted
by
jaw
on Stack Overflow
See other posts from Stack Overflow
or by jaw
Published on 2014-08-19T04:15:37Z
Indexed on
2014/08/19
4:20 UTC
Read the original article
Hit count: 176
pdo
I had a query working just fine, but after converting it to PDO I am getting no results when I do a var_dump($row). But there are no error messages. Can anyone see what I might be doing wrong?
//Here is the original query that worked fine and returned results
global $wpdb;
$results = $wpdb->get_results("SELECT stories.story_name, stories.category, stories.SID,
wp_users.ID, wp_users.display_name FROM stories LEFT JOIN wp_users ON
stories.ID=wp_users.ID where stories.active = 1");
//Here is the query in PDO form which returns no results
$results = $dbh->prepare("select
wp_users.ID,
wp_users.display_name,
stories.SID,
stories.story_name,
stories.category,
FROM stories
LEFT JOIN wp_users ON stories.ID=wp_users.ID
WHERE stories.active=1");
$results->bindParam(':wp_users.ID', $user_ID, PDO::PARAM_INT);
$results->bindParam(':display_name', $display_name, PDO::PARAM_STR);
$results->bindParam(':stories.SID', $SID, PDO::PARAM_INT);
$results->bindParam(':story_name', $story_name, PDO::PARAM_STR);
$results->bindParam(':category', $category, PDO::PARAM_STR);
$results->execute();
$row = $results->fetchAll(PDO::FETCH_ASSOC);
//returns 0 results but should return 8 as original code above did echo var_dump($row);
© Stack Overflow or respective owner