PHP PDO avoids the question mark, so it does not consider it to be a placeholder

I have a query that looks like this:

SELECT CONCAT('path/to/page/?id=', id) AS link FROM users WHERE name = ?

I use PDO to prepare this statement and I get an error

Invalid parameter number: number of bound variables does not match number of tokens

as he considers the question mark in the CONCAT line to be a placeholder.

Is there a way to avoid the question mark, so PDO knows this is not a placeholder?

Please do not leave comments about other ways to get the link. I am changing the old code that is part of the old template engine, so it would be a lot less work to find a way to avoid the question mark than not putting the question mark in the request.

+4
source share
1

PDO . PHP 5.5.15.

$sql = "SELECT CONCAT('path/to/page/?id=', id) AS link FROM foo WHERE name = ?;";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(1, 'name');
$stmt->execute();
print_r($stmt->fetchAll());

, . , , SQL.

, SQL, WHERE FROM . , . , , ( ()).

+4

All Articles