简体   繁体   English

使用SQLite3的PHP PDO错误

[英]PHP PDO error using SQLite3

Here is the code: 这是代码:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if ($_GET['id']) {

    $id = $_GET['id'];

    $db = new SQLite3('database.db');

    $sth = $db->query('SELECT * FROM channels WHERE id = :id');
    $sth->bindValue(':id', $id);

    while ($row = $sth->fetchArray()) {
        var_dump($row);
    }
}
?>

Here is the error message: 这是错误消息:

Fatal error: Call to undefined method SQLite3Result::bindValue() in /var/www/index.html on line 12 致命错误:在第12行的/var/www/index.html中调用未定义的方法SQLite3Result :: bindValue()

I do not understand what Call to undefined method means since I am following the examples on PHP's own website. 我不了解“ Call to undefined method含义,因为我在PHP自己的网站上关注这些示例。

prepare()

Where is that? 哪里是? If you were following the manual correctly you would be preparing a statement and that statement would provide bindValue() method :) 如果您正确地遵循了手册,那么您将准备一个语句,该语句将提供bindValue()方法:)

By executing a query directly on the database handle you don't get the features that statements provide. 通过直接在数据库句柄上执行查询,您将无法获得语句提供的功能。 You have to create an SQLite3Stmt object for it. 您必须为其创建一个SQLite3Stmt对象。

Like this 像这样

$stmt = $db->prepare('SELECT * FROM channels WHERE id=:id');
$stmt->bindValue(':id', $id, SQLITE3_INTEGER);
$result = $stmt->execute();

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM