2

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.

1
  • 3
    You need to call $db->prepare(), not $db->query(). query returns a result set; prepare returns a statement. Commented Feb 8, 2016 at 15:17

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.