user5603796
user5603796

Reputation: 389

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

I do not understand what Call to undefined method means since I am following the examples on PHP's own website.

Upvotes: 2

Views: 506

Answers (1)

Hanky Panky
Hanky Panky

Reputation: 46900

prepare()

Where is that? If you were following the manual correctly you would be preparing a statement and that statement would provide bindValue() method :)

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.

Like this

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

Reference

Upvotes: 3

Related Questions