PHP Velho Oeste 2024

SQLite Functions (PDO_SQLITE)

Introducere

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

Notă:

PDO_SQLITE allows using strings apart from streams together with PDO::PARAM_LOB.

Instalarea

Driver-ul PDO PDO_SQLITE este activat implicit. Pentru a-l dezactiva, puteți folosi opțiunea --without-pdo-sqlite[=DIR], unde opționalul [=DIR] este directorul instalării de bază a sqlite. Începând cu PHP 7.4.0 » libsqlite ≥ 3.5.0 este necesară. Anterior, în locul acesteia, putea fi utilizată biblioteca libsqlite încorporată, și astfel era implicit dacă [=DIR] era omisă.

Notă: Configurări suplimentare pe Windows începând cu PHP 7.4.0

Pentru ca această extensie să funcționeze, anumite fișiere DLL trebuie să fie accesibile în calea de sistem a Windows din variabila PATH. Pentru informații despre cum poate fi realizat acest lucru, accesați FAQ întitulat " Cum să adaug directorul meu PHP la variabila PATH din Windows" pentru informații despre cum să realizați aceasta. Cu toate că copierea fișierelor DLL din directorul PHP în directorul de sistem al Windows de asemenea funcționează (deoarece directorul de sistem este în mod implicit inclus în variabila PATH), acest lucru nu este recomandabil. Această extensie necesită ca următoarele fișiere să existe în calea PATH : libsqlite3.dll.

Cuprins

add a note add a note

User Contributed Notes 4 notes

up
6
ohcc at 163 dot com
3 years ago
With PDO SQLite driver, calculation within an SQL with multiple ? may not get results as you expect.

<?php
// ....
$stmt = $PDO->prepare('SELECT * FROM `X` WHERE `TimeUpdated`+?>?');
$stmt->execute([3600, time()]);
$data = $stmt->fetchAll();
print_r($data);
?>

To get the right results, you have more than 3 solutions.

1. Change '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. Change '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.
up
7
aidan at php dot net
18 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.
up
6
nospam8715 at dririan dot com
11 years ago
Instead of compiling an old version of SQLite to create a database using an older database format that the version of SQLite bundled with PDO can handle, you can (much more easily) just run the query "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 contents of the .dump). That will ensure SQLite creates a database readable by SQLite 3.0 and later.
up
0
Duffalo
17 years ago
Note that as of the date of this post, PDO_SQLITE will not interact with database files created with the current version of the SQLite console application, sqlite-3.3.6.

It is currently necessary to obtain version 3.2.8, available from http://www.sqlite.org/ but only by entering the URI manually, as there is no link. Go to http://www.sqlite.org/download.html and find the URI of the version you're looking for, then make the appropriate version number substitution.
To Top