PDO SQLSTATE [HY093]

时间:2014-12-12 14:42:38

标签: php mysql pdo

<?php
$server   = 'mysql:dbname=test;host=localhost';
$user     = 'root';
$password = '';
$pdo      = new PDO($server, $user, $password);
$pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$test=0;
$teest=3;
$query = $pdo->prepare('SELECT * FROM imgdb LIMIT :staaart,8');
$query -> execute(array('staaart' => $test, 'eeend' => $teest));
$result=$query->fetchAll();
print_r($result);
?>

这是我的PHP / PDO,我收到此警告:

警告:PDOStatement :: execute()[pdostatement.execute]:SQLSTATE [HY093]:参数号无效:绑定变量数与第11行中C:\ xampplite \ htdocs \ pdo_db_connection.php中的标记数不匹配

警告:PDOStatement :: execute()[pdostatement.execute]:SQLSTATE [HY093]:第11行的C:\ xampplite \ htdocs \ pdo_db_connection.php中的参数号无效 Array()

编辑:现在它对我有用

$server   = 'mysql:dbname=test;host=localhost';
$user     = 'root';
$password = '';
$pdo      = new PDO($server, $user, $password);
$pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$test=0;
$teest=2;
$teeest='Bochum';
$query = $pdo->prepare('SELECT * FROM imgdb WHERE stadt = :stadt LIMIT :staaart,:eeend');
$query->bindParam(':stadt', $teeest, PDO::PARAM_STR);
$query->bindParam(':staaart', $test, PDO::PARAM_INT);
$query->bindParam(':eeend', $teest, PDO::PARAM_INT);
$query -> execute();
$result=$query->fetchAll();
print_r($result);

1 个答案:

答案 0 :(得分:0)

您准备好的查询中只有一个参数,但正在尝试绑定两个参数:

$query = $pdo->prepare('SELECT * FROM imgdb LIMIT :staaart,8');
$query -> execute(array('staaart' => $test, 'eeend' => $teest));

准备staaarteeend

$query = $pdo->prepare('SELECT * FROM imgdb LIMIT :staaart,:eeend');
$query -> execute(array('staaart' => $test, 'eeend' => $teest));

或仅使用staaart

执行
$query = $pdo->prepare('SELECT * FROM imgdb LIMIT :staaart,8');
$query -> execute(array('staaart' => $test));