How to update data in SQLite table using php?

Viewed 3280

I am working on a php code as shown below:

class MyDB extends SQLite3
{
    function __construct()
    {
        $this->open('database/Podcast.db');
    }
}
$db = new MyDB();

$f = $mp4_files[$_POST['id']];

$parts = pathinfo($f);

switch ($parts['extension']) {
        /* Conversion of mp4 into mp3 is happening */
}

print_r($f); // Line Z

$result = $db->exec("UPDATE Podcast_Export SET Status = 'Completed' WHERE House_number = '" . $f . "'"); // Line A

if ($result == FALSE) {
    echo "Error in fetch " . $db->lastErrorMsg(); // Line M
}

At Line Z, on console it prints 36031P.mp4 (When Go button is clicked from the 1st table row (from UI))

At Line Z, on console it prints hello.mp4 (When Go button is clicked from the 2nd table row(from UI))


Problem Statement:

I have a query at Line A in order to update Podcast_Export table but its not working and throwing error at Line M:

Error in fetch database is locked

At this moment, I have the following content inside Podcast_Export table:

enter image description here

The SQLite version which I am using is 3.27.2

2 Answers

From the php SQLITE3 doc

SQLite3::exec — Executes a result-less query against a given database

It returns a boolean. "Resultless" query is typcially an INSERT, UPDATE, DELETE but not a SELECT.

You might want to investigate how you could use querySingle to get the desired result.

Related