user5603796 February 2016

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.

Answers


Hanky Panky February 2016

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

Post Status

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

Search




Leave an answer