致命错误:消息“未在查询/准备好的语句中使用索引"的未捕获异常"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);
这是能干的模式-
--
-- 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;
推荐答案
Take a look at this bug-report : #35450
mysqli extension reports too many warnings
引用便笺的几句话:
Mysqli扩展名抛出太多 警告.
例如,"SELECT * FROM table"会产生警告: 警告:mysqli :: query():无索引 用于查询/准备的语句中 SELECT * FROM table ..."
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()
禁用它.
不幸的是,不推荐使用该功能.
Humph, unfortunately, that function is deprecated...
这篇关于致命错误:消息“未在查询/准备好的语句中使用索引"的未捕获异常"mysqli_sql_exception"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!