如果将PDO :: ATTR_EMULATE_PREPARES属性设置为false,则不会引发Mysql存储功能的无效参数错误。
MySQL存储功能(示例)
CREATE DEFINER=`tester`@`%` FUNCTION `blabla`(`item` TEXT, `no` INT, `option` TINYINT, `type` VARCHAR(1))....
PDO :: ATTR_EMULATE_PREPARES = false
<?php
$dbh = new PDO('mysql:......
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$sql = "SELECT blalba('test', 1, 'a')"; // <-- set invalid argument, expected 4
$stmt = $dbh->prepare($sql);
$stmt->execute();
print_r($stmt->errorInfo);
// result ==>
Array
(
[0] => 00000
[1] =>
[2] =>
)
PDO :: ATTR_EMULATE_PREPARES = true
<?php
$dbh = new PDO('mysql:......
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$sql = "SELECT blalba('test', 1, 'a')"; // <-- set invalid argument, expected 4
$stmt = $dbh->prepare($sql);
$stmt->execute();
print_r($stmt->errorInfo);
// result ==>
Array
(
[0] => 42000
[1] => 1318
[2] => Incorrect number of arguments for FUNCTION project.BLABLA; expected 4, got 3
)