(PHP 5 >= 5.3.0)
SQLite3::exec — Executes a result-less query against a given database
$query
)Executes a result-less query against a given database.
query
The SQL query to execute (typically an INSERT, UPDATE, or DELETE query).
Returns TRUE
if the query succeeded, FALSE
on failure.
Example #1 SQLite3::exec() example
<?php
$db = new SQLite3('mysqlitedb.db');
$db->exec('CREATE TABLE bar (bar STRING)');
?>
gamag (2013-03-06 21:02:12)
SQLite needs to create some temp-files (journals...) to execute certain statements, so php needs write-permission in your db-directory.
info at tellmatic dot org (2013-01-16 15:50:26)
IMPORTANT! just a note:
weird behaviour when doing an exec on a sqlite db!!!
if want to execute a query on a sqlite db with exec, and your dbfile already was e.g. mode 777, and you get some php errors saying
"SQLite3::exec(): unable to open database file in ...."
and you get crazy while debugging, just add write üermissions to the whole directory for the user the webserver/php runs.
this behaviour makes absolutely NO sense, and is a source of frustration.
at least a more meaningful errormessage would be nice.
i couldnt figure out why sqlite needs write permissions for the whole dir instead of only one file. this is stupid and must be a bug!
(to be secure you have to create a directory with write permissions only for php/apache)
moodsey211 at gmail dot com (2010-12-16 15:29:10)
If you get the error message saying "SQLite3::exec. database locked." You just need to define a busyTimeout to work around this.