致命错误:未捕获的异常“mysqli_sql_exception",消息为“查询/准备语句中未使用索引" [英] Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'No index used in query/prepared statement'
问题描述
当我运行以下代码时,出现错误提示
When I run the following code, I get the error saying
致命错误:未捕获的异常'mysqli_sql_exception' 带有消息'在查询/准备中没有使用索引声明'
Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'No index used in query/prepared statement'
$mysql = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database');
if (mysqli_connect_errno()) {
printf("DB error: %s", mysqli_connect_error());
exit();
}
$get_emp_list = $mysql->prepare("SELECT id, name FROM calc");
if(!$get_emp_list){
echo "prepare failed\n";
echo "error: ", $mysql->error, "\n";
return;
}
$get_emp_list->execute();
$get_emp_list->bind_result($id, $emp_list);
这是有能力的模式 --
And this is the able schema --
--
-- Table structure for table `calc`
--
CREATE TABLE IF NOT EXISTS `calc` (
`id` int(12) NOT NULL,
`yr` year(4) NOT NULL,
`mnth` varchar(12) NOT NULL,
`name` varchar(256) NOT NULL,
`paidleave` int(12) NOT NULL,
`balanceleave` int(12) NOT NULL,
`unpaidleave` int(12) NOT NULL,
`basesalary` int(12) NOT NULL,
`deductions` int(12) NOT NULL,
`tds` int(12) NOT NULL,
`pf` int(12) NOT NULL,
`finalsalary` int(12) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
推荐答案
看看这个错误报告:#35450
mysqli 扩展报告太多警告
引用笔记中的几句话:
Mysqli 扩展抛出太多警告.
例如,"SELECT *从表"导致警告:"警告:mysqli::query(): 没有索引用于查询/准备语句SELECT * FROM 表..."
Mysqli extension throws too many warnings.
For example, "SELECT * FROM table" results in a warning: "Warning: mysqli::query(): No index used in query/prepared statement SELECT * FROM table ..."
而且,引用另一个注释,这看起来很有趣:
And, quoting another note, which seems interesting :
使用 mysqli_report()
来禁用它.
这篇关于致命错误:未捕获的异常“mysqli_sql_exception",消息为“查询/准备语句中未使用索引"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!