mysqli致命错误:查询/准备好的语句中未使用索引 [英] mysqli fatal error: No index used in query/prepared statement

查看:58
本文介绍了mysqli致命错误:查询/准备好的语句中未使用索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用mysqli执行一个简单的准备好的语句,但是它不起作用.

I want to execute a simple prepared Statement using mysqli, but it won't work.

我有这张桌子:

CREATE TABLE IF NOT EXISTS `account` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(100) COLLATE latin1_german2_ci NOT NULL,
  `password` varchar(100) COLLATE latin1_german2_ci NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci AUTO_INCREMENT=4 ;

并要打印特定电子邮件的ID.

And want to print the id of a specific email.

$mysqli = new mysqli($server,$user,$pass,$db);

if(mysqli_connect_errno()) {
    echo "Connection Failed: " . mysqli_connect_errno();
    exit();
 }
 $user = "test@dada.com";
 $pass = "dada";
/* Create a prepared statement */
if($stmt = $mysqli -> prepare("SELECT * FROM account WHERE email=?
AND password=?")) {

  /* Bind parameters
     s - string, b - blob, i - int, etc */
  $stmt -> bind_param("ss", $user, $pass);

  /* Execute it */
  $stmt -> execute();

  /* Bind results */
  $stmt -> bind_result($result);

  /* Fetch the value */
  $stmt -> fetch();

  echo $user . "id of user is " . $result;

  /* Close statement */
  $stmt -> close();
}

/* Close connection */
$mysqli -> close();

但是我收到以下错误消息:

But i get following Error:

严重错误:未捕获的异常'mysqli_sql_exception',消息为'在查询/准备好的语句中未使用索引SELECT * FROM account WHERE email =? AND password =?' mysqli_stmt-> execute()#1 {main}

Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'No index used in query/prepared statement SELECT * FROM account WHERE email=? AND password=?' mysqli_stmt->execute() #1 {main}

推荐答案

好吧,我认为您必须这样做:

Well I think you have to do this:

CREATE TABLE IF NOT EXISTS `account` (
  `id` PRIMARY KEY int(11) NOT NULL AUTO_INCREMENT,
   // the rest

上面的代码将表的id字段设置为PRIMARY KEY,因此它永远不会重复,并且仍然是表的索引.

The above code makes the id field of your table as PRIMARY KEY so it never repeats itself and it remains the index of your table.

这篇关于mysqli致命错误:查询/准备好的语句中未使用索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆