Home Ask Login Register

Developers Planet

Your answer is one click away!

user5603796 February 2016

PHP PDO error using SQLite3

Here is the code:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
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()) {

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.


Hanky Panky February 2016


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();


Post Status

Asked in February 2016
Viewed 2,648 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life