|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-05-09 09:44 UTC] alvaro at demogracia dot com
Description: ------------ 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. [1] http://php.net/manual/en/pdostatement.bindvalue.php [2] https://stackoverflow.com/questions/17386469/pdo-prepared-statement-what-are-colons-in-parameter-names-used-for Test script: --------------- <?php $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); $sth->execute(); var_dump($sth->fetch(PDO::FETCH_ASSOC)); PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 01:00:01 2025 UTC |
I refer to the overall extension, e.g.: <?php $sth = $dbh->prepare('SELECT :text AS greeting FROM DUAL'); $sth->execute(array('text' => 'Hello, World!')); var_dump($sth->fetch(PDO::FETCH_ASSOC)); ?> ... appears to work too despite the respective manual entry [1] showing colons all around. [1] http://php.net/manual/en/pdostatement.execute.php