I'm trying to rewrite all of my standard MySQLi queries to MySQLi Prepared Statements.
I've noticed a problem though, whenever I have a variable that contains a hyphen, the execute() fails.
The variables I'm dealing with ($project_id) look like this: 'AAD0012003-01'.
$get_progress_done = $db->prepare("SELECT COUNT(*) as rows FROM testvoorstage_checklists.?");
$get_progress_done->bind_param("s", $project_id);
$get_progress_done->execute();
$get_progress_done->store_result();
$get_progress_done->bind_result($rows);
while($get_progress_done->fetch()) {
echo $rows;
}
I've been searching for a solution for a couple of days now, and I still haven't found a way to 'escape' the hyphen in a variable.
I know the queries do work, because I've tried them in PHPMyAdmin with a set variable and they are working fine there.
I'm learning Prepared Statements, and I would love to know how to fix this because I have quite alot of variables that contain special characters.
The error I'm getting is:
Call to a member function bind_param() on a non-object