When you instantiate the PDO, you need to tell it to use prepared MySQL queries:
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
, PHP >= 5.3, mysqlnd, .
:
$ php -a
Interactive shell
php > $db = PDO("mysql:host=localhost;dbname=test", "test", "");
php > $res = $db->query("SELECT 1, PI()");
php > var_dump($res->fetch());
array(4) {
[1]=>
string(1) "1"
[2]=>
string(1) "1"
["PI()"]=>
string(8) "3.141593"
[3]=>
string(8) "3.141593"
}
php > $db = PDO("mysql:host=localhost;dbname=test", "test", "", [PDO::ATTR_EMULATE_PREPARES=>false]);
php > $res = $db->query("SELECT 1, PI()");
php > var_dump($res->fetch());
array(4) {
[1]=>
int(1)
[2]=>
int(1)
["PI()"]=>
float(3.1415926535898)
[3]=>
float(3.1415926535898)
}
php >