Does SELECT COUNT(*) work with MySQLi prepared statements?

Posted by wordman on Stack Overflow See other posts from Stack Overflow or by wordman
Published on 2012-12-04T23:00:21Z Indexed on 2012/12/04 23:03 UTC
Read the original article Hit count: 175

Filed under:
|
|

I'm working on a test page and am using MySQLi prepared statements in my queries after reading they make my code safe from SQL injection. I have been successful with prepared statements so far with retrieving data from my DB, that all works great.

What I want to do now is count the number of galleries within a project using SELECT COUNT(*). That's it.

Without using a prepared statement, my old query looked like this:

// count number of galleries per project
$conn = dbConnect('query');
$galNumb = "SELECT COUNT(*) FROM pj_galleries WHERE project = {$pjInfo['pj_id']}";
$gNumb = $conn->query($galNumb);
$row = $gNumb->fetch_row();
$galTotal = $row[0];

But for all my reading and searching the internet, I can not find out the proper way to write this as a prepared statement. I'm no PHP whiz here, and not coding daily isn't helping my skills.

If I've missed anything please ask. Many thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about mysqli