以下代码执行错误查询。输入数据显然是错误的。即使有这些错误,MySQLi也不会报告错误。PHP和MySQLi - 错误查询并且没有错误
<?php
$mysqli = new MySQLi('hostname', 'username', 'password', 'databasename');
$sql = '
SELECT
ID_ASSOCIADO
FROM
MOVIMENTO
WHERE
DATA_MOVIMENTO BETWEEN ? AND ?
';
$mysqliStmt = $mysqli->prepare($sql);
$dataInicial = "2013-02-0'"; // Malformed date.
$dataFinal = '2013-02-"'; // Another one.
$mysqliStmt->bind_param('ss', $dataInicial, $dataFinal);
$mysqliStmt->execute();
$mysqliStmt->bind_result($idAssociado);
while ($mysqliStmt->fetch()) {
echo 'ID ASSOCIADO: ' . $idAssociado . PHP_EOL;
}
?>
的准备调用后的mysqli对象:
mysqli Object
(
[affected_rows] => -1
[client_info] => 5.5.29
[client_version] => 50529
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[error_list] => Array
(
)
[field_count] => 0
[host_info] => Localhost via UNIX socket
[info] =>
[insert_id] => 0
[server_info] => 5.5.28-1
[server_version] => 50528
[stat] => Uptime: 9651 Threads: 1 Questions: 1947 Slow queries: 0 Opens: 1433 Flush tables: 1 Open tables: 340 Queries per second avg: 0.201
[sqlstate] => 00000
[protocol_version] => 10
[thread_id] => 481
[warning_count] => 0
)
mysqli的对象执行调用后:
mysqli Object
(
[affected_rows] => -1
[client_info] => 5.5.29
[client_version] => 50529
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[error_list] => Array
(
)
[field_count] => 1
[host_info] => Localhost via UNIX socket
[info] =>
[insert_id] => 0
[server_info] => 5.5.28-1
[server_version] => 50528
[stat] => Commands out of sync; you can't run this command now
[sqlstate] => HY000
[protocol_version] => 10
[thread_id] => 481
[warning_count] => 0
)
我必须把错误在库MySQLi像PDO?
为什么要这个报告错误?你查询的数据,你没有得到任何。就是这样,你的查询仍然有效。 – Oliver 2013-03-08 16:19:57