SQLite3::exec

(PHP 5 >= 5.3.0)

SQLite3::execExécute une requête sur une base de données

Description

public bool SQLite3::exec ( string $query )

Exécute une requête sur une base de données.

Liste de paramètres

query

La requête SQL à exécuter (typiquement, une requête de type INSERT, UPDATE ou DELETE).

Valeurs de retour

Retourne TRUE si la requête a été exécutée avec succès, FALSE si une erreur survient.

Exemples

Exemple #1 Exemple avec SQLite3::exec()

<?php
$db 
= new SQLite3('mysqlitedb.db');

$db->exec('CREATE TABLE bar (bar STRING)');
?>

add a note add a note

User Contributed Notes 5 notes

up
8
gamag
1 year ago
SQLite needs to create some temp-files (journals...) to execute certain statements, so php needs write-permission in your db-directory.
up
3
Rob Haverkort
1 year ago
Actually, sqlite creates a journal-file when changing data and so it needs the write-permissions in the directory.
up
1
moodsey211 at gmail dot com
3 years ago
If you get the error message saying "SQLite3::exec. database locked." You just need to define a busyTimeout to work around this.
up
0
namibj
25 days ago
If you see one or more notes here stating that you need write access to the directory your db is in, than consider them explained. If you do not see any of them, just ignore the first paragraph in this note.

So, if you use WAL (Write-Ahead Log) (link to sqlite doc for this: http://sqlite.org/wal.html ), it needs write acces because of the implementation of multi-thread access to one db. You can turn it off, if you do not want to give the dir write access, but you can also create a certain file it needs (see the link for a description, as it is explained very well there) that you need write access to and you may get away using WAL without giving write accesss to the dir.
up
-5
info at tellmatic dot org
1 year ago
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)
To Top