Reputation: 89
I have this query that executes properly:
$query = $handler->prepare("SELECT * FROM pm WHERE ((user1 = $userid AND user1read = 'no') OR (user2 = $userid AND user2read = 'no') AND id2 = '1')");
$query->execute();
When I try to declare tokens, it throws an Invalid parameter number'
fatal error. This is the code that throws the error:
$query = $handler->prepare("SELECT * FROM pm WHERE ((user1 = :userid AND user1read = 'no') OR (user2 = :userid AND user2read = 'no') AND id2 = '1')");
$query->execute(array(
'userid' => $userid
));
I'm trying to migrate from sql to PDO. Is there some sql remnant here that I'm missing?
Upvotes: 0
Views: 66
Reputation: 12101
+1 to @djdy. But ,if I'm not mistaken, you can try using PDO::ATTR_EMULATE_PREPARES
and its will work :
$handler->setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);
$query = $handler->prepare("SELECT * FROM pm WHERE ((user1 = :userid AND user1read = 'no') OR (user2 = :userid AND user2read = 'no') AND id2 = '1')");
$query->execute(array(
'userid' => $userid,
));
Upvotes: 1
Reputation: 6919
You cannot use a named parameter marker of the same name twice in a prepared statement
Source: http://php.net/manual/de/pdo.prepare.php
Try:
$query = $handler->prepare("SELECT * FROM pm WHERE ((user1 = :userid AND user1read = 'no') OR (user2 = :userid2 AND user2read = 'no') AND id2 = '1')");
$query->execute(array(
'userid' => $userid,
'userid2' => $userid
));
Upvotes: 3