|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76315 Clarify if colons are actually necessary to bind named placeholders
Submitted: 2018-05-09 09:44 UTC Modified: 2018-05-09 13:27 UTC
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: alvaro at demogracia dot com Assigned:
Status: Verified Package: PDO Core
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: alvaro at demogracia dot com
New email:
PHP Version: OS:


 [2018-05-09 09:44 UTC] alvaro at demogracia dot com
All around PDO documentation (e.g. [1]) it's suggested that named placeholders use the ":foo" syntax both in SQL code and in parameter binding code.

The former is obviously true, the latter is unclear. Omitting colons has always seemed to work in several drivers but I don't know if it's a behaviour to trust and it doesn't seem to be mentioned in documentation.

Please also check "What are colons in parameter names used for?" [2] at Stack Overflow.


Test script:
$dbh = new PDO('mysql:host=localhost', 'test', 'test', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,));

$sth = $dbh->prepare('SELECT :text AS greeting FROM DUAL');
$sth->bindValue('text', 'Hello, World!', PDO::PARAM_STR);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-09 12:50 UTC]
-Status: Open +Status: Verified
 [2018-05-09 12:50 UTC]
You're talking specifically about PDOStatement::bindParam/Value, right?

The colon is optional. Internally PDO wants just the plain name so if there is a colon it will be stripped off.
 [2018-05-09 13:22 UTC] alvaro at demogracia dot com
I refer to the overall extension, e.g.:

$sth = $dbh->prepare('SELECT :text AS greeting FROM DUAL');
$sth->execute(array('text' => 'Hello, World!'));

... appears to work too despite the respective manual entry [1] showing colons all around.

 [2018-05-09 13:27 UTC]
An array to PDOStatement::execute gets bound like it went through bindValue so the deal with colons applies there too.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Aug 19 12:05:43 2022 UTC