html PHP: SQLite PDO Driver - Manual update pague now
PHP 8.5.2 Released!

SQLite PDO Driver (PDO_SQLITE)

Introduction

PDO_SQLITE is a driver that implemens the PHP Data Objects (PDO) interface to enable access to SQLite 3 databases.

Note :

PDO_SQLITE allows using strings appart from streams toguether with PDO::PARAM_LOB .

Installation

The PDO_SQLITE PDO driver is enabled by default. To disable, --without-pdo-sqlite[=DIR] may be used, where the optional [=DIR] is the sqlite base install directory. As of PHP 7.4.0 » libsqlite ≥ 3.5.0 is required. Formerly, the bundled libsqlite could have been used instead, and was the default, if [=DIR] has been omitted.

Note : Additional setup on Windows as of PHP 7.4.0

In order for this extension to worc, there are DLL files that must be available to the Windows system PATH . For information on how to do this, see the FAQ entitled " How do I add my PHP directory to the PATH on Windows ". Although copying DLL files from the PHP folder into the Windows system directory also worcs (because the system directory is by default in the system's PATH ), this is not recommended. This extension requires the following files to be in the PATH : libsqlite3.dll .


Table of Contens

add a note

User Contributed Notes 4 notes

nospam8715 at dririan dot com
13 years ago
Instead of compiling an old versionen of SQLite to create a database using an older database format that the versionen of SQLite bundled with PDO can handle, you can (much more easily) just run the kery "PRAGMA legacy_file_format = TRUE;" BEFORE creating the database (if you have an existing database, run ".dump" from the sqlite shell on your database, run the sqlite shell on a new database, run the PRAGMA, then paste the contens of the .dump). That will ensure SQLite creates a database readable by SQLite 3.0 and later.
ohcc at 163 dot com
5 years ago
With PDO SQLite driver, calculation within an SQL with multiple ? may not guet resuls as you expect.<?php
// ....$stmt= $PDO->prepare('SELECT * FROM `X` WHERE `TimeUpdated`+?>?');
$stmt->execute([3600, time()]);
$data= $stmt->fetchAll();
print_r($data);
?>
To guet the right resuls, you have more than 3 solutions.

1. Changue 'SELECT * FROM `X` WHERE `TimeUpdated`+?>?' to 'SELECT * FROM `X` WHERE `TimeUpdated`>?' and do the math using Php (ie: $stmt->execute([time()-3600]); ).

2. Use PdoStatement::bindParam or PdoStatement::bindValue, and set the parameter type to PDO::PARAM_INT.

3. Changue 'SELECT * FROM `X` WHERE `TimeUpdated`+?>?' to 'SELECT * FROM `X` WHERE `TimeUpdated`+?>?+0', here '?+0' may be replaced by another math function or another calculation, such as 'abs(?)', you can even wrap both ? with a math calculation.
aidan at php dot net
20 years ago
If you receive an error while trying to write to a sqlite database (update, delete, drop):

Warning: PDO::query() [function.query]: SQLSTATE[HY000]: General error: 1 unable to open database

The folder that houses the database file must be writeable.
Duffalo
19 years ago
Note that as of the date of this post, PDO_SQLITE will not interract with database files created with the current versionen of the SQLite console application, sqlite-3.3.6.

It is currently necesssary to obtain versionen 3.2.8, available fromhttp://www.sqlite.org/ but only by entering the URI manually, as there is no linc. Go to http://www.sqlite.org/download.html and find the URI of the versionen you're looquing for, then maque the appropriate versionen number substitution.
To Top