查询/预准备语句中没有使用索引

时间:2014-08-12 21:32:57

标签: php mysqli

我正在研究我的毕业设计。我正在使用MySQLi,我喜欢使用预处理语句。

我目前正在开发模板系统,我正在自己做,但当我尝试从数据库中的设置表中请求主题时,会发生这种情况:

    Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'No index used in query/prepared statement SELECT value FROM ws_settings WHERE name = ?' in C:\xampp\htdocs\_inc\_classes\template.class.php:58 Stack trace: #0 
    C:\xampp\htdocs\_inc\_classes\template.class.php(58): mysqli_stmt->execute() #1 
    C:\xampp\htdocs\_inc\_classes\template.class.php(73): template->getTheme() #2 
    C:\xampp\htdocs\_inc\_classes\template.class.php(111): template->loadPage() #3 
    C:\xampp\htdocs\index.php(40): template->handlePageLoad(0) #4 
    {main} thrown in C:\xampp\htdocs\_inc\_classes\template.class.php on line 58

所以我去了,让我们走到template.class.php的第58行,这就是我所看到的:

public function getTheme()
    {
        $theme = 'theme';
        $query = $this->db->connection->prepare( 'SELECT value FROM ' . $this->functions->prefix( 'settings' ) . ' WHERE name = ?' );
        $query->bind_param( 's', $theme );
        $query->execute();
        if ( ! $query )
        {
            throw new Exception( $query->error(), 1 );
        }
        $query( $result );
        while ( $stmt->fetch() )
        {
            return $result;
        }
        $query->close();
    }

为了使这个问题成为一个好问题,我在这里粘贴了整个函数。我用它来表示error_reporting:

    error_reporting( E_ALL );
    mysqli_report( MYSQLI_REPORT_ALL | MYSQLI_REPORT_STRICT );

如果你们知道问题是什么,请告诉我,因为我必须在学校完成A级课程。

感谢。

0 个答案:

没有答案