Reputation: 10228
I have a query like this:
" SELECT IF(table.edited > 0, '<i title="c.edited"></i>','') AS edited, ... "
^ ^ ^
The above query has a pdo-syntax-error ...! It is about quote. How can I fix it?
Upvotes: 0
Views: 492
Reputation: 10228
Try this:
" SELECT IF(table.edited > 0, CONCAT('<i title=\"', c.edited, '\"></i>','') AS edited, ..."
Using CONCAT for combining both c.edited
and a string.
Using \
for escaping quote (as @Aaron Mason mentioned in his answer)
Upvotes: -1
Reputation: 3815
use PDO bindValue to insert clean string:
$query = "SELECT filename
FROM Posters
WHERE name = :name";
$statement = $this->db->prepare($query);
$statement->bindValue(':name', $name);
$statement->execute();
return $statement->fetchAll(PDO::FETCH_ASSOC);
Upvotes: 1
Reputation: 362
Backslashes, same as any other string in PHP with quotes in it:
" SELECT IF(table.edited > 0, '<i title=\"c.edited\"></i>','') AS edited, ... "
Upvotes: 1