public static function whereHelper($whereClause)
{
$strData = 'WHERE ';
foreach($whereClause as $value)
{
$strData = $strData . ' ' . $value;
}
return $strData;
}
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id = 5
$whereClause = array("id", "=", 5);
$sql = 'DELETE FROM ' . self::$table .' '. self::whereHelper($whereClause); [\\PHP]
I just added small space ...' ' , and it worked.
What you need to do in such scenario’s Emeka, is you need to see the query that’s actually being sent to the database. The easiest and crudest way to do this, is to just echo it out. If I encountered this problem, the first I would have done, is do this…
echo $sql;
Troubleshooting a dynamically generated query, without seeing the resulting query that’s sent to the database server, is not an easy task. In your case, if you echo’d out this query, you would have seen this…
[mysql]
DELETE FROM tableWHERE id = 5;
[/mysql]
And so you would have immediately seen where the problem is.