小编典典

致命错误:消息“未在查询/准备好的语句中使用索引”的未捕获异常“ mysqli_sql_exception”

mysql

当我运行以下代码时,出现错误提示

致命错误:消息“未在查询/准备好的语句中使用索引”的未捕获异常“ mysqli_sql_exception”

$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;

阅读 331

收藏
2020-05-17

共1个答案

小编典典

看一下这个错误报告: #35450
mysqli扩展报告了太多警告

引用笔记的几句话:

Mysqli扩展名抛出太多警告。
例如,“ SELECT * FROM table”将导致警告:“警告:mysqli :: query():查询/准备好的语句SELECT * FROM
table中未使用索引…”

并且,引用另一个注释,这似乎很有趣:

使用mysqli_report()禁用该。

不幸的是,该功能已被弃用…

2020-05-17