lundi 29 décembre 2014

PDO SQLite cannot update record: "database is locked"

I'm struggling with this all day. I've read numerous posts, tried all suggestions but nothing works.


This is my PHP code:



try {
$db = new PDO('sqlite:test.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$result = $db->query('SELECT * FROM v_test');

foreach ($result as $row) {
echo $row['column1'] . " | " . $row['column2'] . "<br>";

/**************************************
* Update table *
**************************************/
if (!$db->exec("update test set column2 = date('now') where column1 ='" . $row['column1'] . "';") === TRUE) {
echo "Cannot update date:" . $db->lastErrorMsg();
$db = null;
exit;
}
}

/**************************************
* Close db connections *
**************************************/
$db = null;
}
catch(PDOException $e) {
echo "PDOException: " . $e->getMessage() . "<br>";

/*** show the error info ***/
foreach($db->errorInfo() as $error)
{
echo $error.'<br />';
}

$db = null;
}


I run PHP v5.3.3. With just the loop after the select I get the correct values from the table, so I can access the database, which is in the same folder as my script. The folder has 0777 rights, the database and the script both have 0660, but I've also tried with 0777. But when I try to update a record I get the 'database is locked' error.


I've used the same database before on a different server, but not with PDO but with $db = new SQLite3('mailing.db', SQLITE3_OPEN_READWRITE); I couldn't use the same script because SQLITE isn't enabled on the new server, but PDO_SQLITE is.


My phpinfo() says:



  • PDO drivers mysql, odbc, pgsql, sqlite

  • pdo_sqlite. PDO Driver for SQLite 3.x enabled SQLite Library 3.3.6

  • '--without-sqlite'

  • '--without-sqlite3'


Of course I tried to enable SQLite on the new server first so I could use the original script. But because I'm not a system engineer (just a developer ;)) I had hoped I could use the PDO option.


Is my problem related to my PHP configuration or is my script wrong?


Aucun commentaire:

Enregistrer un commentaire