0

I'm currently switching my site over to PDO and I'm running into a few issues, and sadly I don't know enough to figure it out.

I have this query

$localnewssql = "SELECT n.newsID, n.type, n.title, n.headline, n.tagline, n.body, n.tags, n.date, ni.imageID, i.imageID, i.filename FROM tbl_news_articles AS n 
        LEFT JOIN tbl_news_images AS ni ON ni.newsID = n.newsID 
        LEFT JOIN tbl_images AS i ON i.imageID = ni.imageID
        WHERE n.tags LIKE ? 
        ORDER BY n.date DESC LIMIT 0, 6";
$param = "%sennen%";
$stmt = $conn->prepare($localnewssql);
$stmt->execute($param);
$localnews_data = $stmt->fetchAll();

but nothing is being returned when I foreach loop $localnews_data. Can someone please help me understand this?

My old MySQL code which was returning results was:

$localnewssql = "SELECT n.newsID, n.type, n.title, n.body, n.tags, n.date, ni.imageID, i.imageID, i.filename FROM tbl_news_articles AS n 
        LEFT JOIN tbl_news_images AS ni ON ni.newsID = n.newsID 
        LEFT JOIN tbl_images AS i ON i.imageID = ni.imageID
        WHERE n.tags LIKE '%sennen%' 
        ORDER BY n.date DESC LIMIT 0, 6";
$localnewsresult = mysqli_query($conn,$localnewssql);

Not sure why the PDO version is returning a blank array?

any ideas? many thanks

Nick
  • 138,499
  • 22
  • 57
  • 95
BBLJ84
  • 175
  • 1
  • 12

1 Answers1

2

You need to pass an array of parameter values to PDOStatement::execute, where you are passing only a string. Put $param in an array and it will work i.e.

$stmt->execute(array($param));
Nick
  • 138,499
  • 22
  • 57
  • 95