php5-sqlite3 does not add PDO driver

Bug #178906 reported by Brian Hysell
26
This bug affects 3 people
Affects Status Importance Assigned to Milestone
php-sqlite3 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Binary package hint: php5-sqlite3

Command executed: "sudo aptitude install apache2 libapache2-mod-php5 php5-sqlite3".

After restarting Apache, phpinfo(); shows that PDO has no database drivers installed, despite having installed the php5-sqlite3. Using PDO is the only way to access SQlite3 from PHP (except for some immature extension on PECL that models its API after the PHP extension for SQLite2, but that's not relevant here).

After installing SQlite2 for PHP ("sudo aptitude install php5-sqlite") and restarting Apache, both SQlite 2 and 3 are successfully added as PDO drivers.

Revision history for this message
Brian Hysell (briandh) wrote :

Oops, I forgot to mention that I'm running Ubuntu Gutsy Gibbon.

Revision history for this message
MelkorLord (melkorlord) wrote :

Hi,

I second this request as this is VERY annoying not to be able to use SQLite3 at all within PHP!

Installing "php5-sqlite" adds support for "sqlite" and "pdo_sqlite" extensions which is fine but limited to SQLite 2.x databases.

Installation "php5-sqlite3" adds support for "sqlite3" extension but it is absolutely _unusable_ with PHP. The PHP site here http://www.php.net/manual/en/book.sqlite3.php shows how we should use the extension but trying to instantiate the the PDO style class "SQLite3" resulted in the error :

PHP Fatal error: Class 'SQLite3' not found in /path/to/file.php

So, could this issue be fixed so we can fully use SQLite3 with PHP?

Revision history for this message
MelkorLord (melkorlord) wrote :

Hi,

After further investigation, I realise that I was fooled :-) Upstream PHP only support SQLite 2.x, either via PDO or classic function calls such as sqlite_xxx().

SQLite3 is _NOT YET_ supported in upstream PHP.

There's an external project at http://php-sqlite3.sf.net which provides support for SQLite 3.x via classic function calls such as sqlite3_xxx() as well as a PEAR::DB class.

So, until upstream PHP adds support to SQLite3 (classic functions and PDO), this "bug" is considered irrelevant.

Revision history for this message
Brian Hysell (briandh) wrote :

That incorrect, as far as I know. Upstream PHP does support SQLite3 -- at least for current stable versions of PHP -- via PDO, as indicated in the documentation: http://us.php.net/manual/en/ref.pdo-sqlite.php

I believe that a "classic" interface to SQLite3 is unsupported simply because unlike other RDBMSs, SQLite3 didn't have an existing legacy interface that had to be maintained for compatibility's sake at the time of its implementation as a driver for PDO, which was intended to become the standard means of interfacing with RDBMSs in PHP. That is, however, primarily inference on my part.

Additionally, your bug appears to be different from mine. My bug does not pertain to any SQLite3 extension; it pertains to the SQLite3 driver for PDO not being installed unless the SQLite2 package is installed as well.

Revision history for this message
MelkorLord (melkorlord) wrote :

Ok Brian, you're right for some parts. Upstream PHP DOES support SQLite3, through PDO indeed and I think the same way about the unsupported "classic" interface to SQLite3.

Although you're right about the PDO driver not being installed unless SQLite2 package is installed, it must be noted that this PDO driver is only valid for old SQLite2 databases. You _WON'T_ open any SQLite3 database with this PDO driver.

In fact, we have the same problem, our inability to use SQLite3 databases in a way natively supported by PHP (PDO::SQLite3).

Currently, the only way to manipulate SQLite3 databases is to install package "php5-sqlite3" which comes from a different project, not from PHP itself.

Debian/Ubuntu PHP packages should provide SQLite3 support using PDO and I don't know why this isn't the case currently.

PS: I have the same problem with Gentoo distribution. There's a USE flag named "sqlite" which builds a "pdo_sqlite.so" but can only handle SQLite2 databases. Strangely enough, building (emerging) PHP on Gentoo with "sqlite" USE flag imposes a dependency on both "sqlite-2.x" and "sqlite-3.x"
 packages (ebuilds).

Revision history for this message
Brian Hysell (briandh) wrote :

"In fact, we have the same problem, our inability to use SQLite3 databases in a way natively supported by PHP (PDO::SQLite3)."

My problem was as follows:
-> Upon installing php5-sqlite3, the sqlite driver is not added to PDO, and I cannot connect to an SQLite3 database
-> Upon installing php5-sqlite in addition to the aformentioned package, both the "sqlite" (3) and "sqlite2" drivers are added to PDO, and I _can_ connect to an SQLite3 database

Caveats:
-> I've only tested this process under Gutsy, and my Ubuntu-laden notebook recently died
-> I have not tested by first installing php5-sqlite, and then installing php5-sqlite3

However, on a hunch, I've looked within the deb files of both packages in Gutsy's repos, and I believe I've found the issue.

Both packages contain the proper shared objects: sqlite.so ("classic interface") and pdo_sqlite.so for php5-sqlite; pdo_sqlite3.so for php5-sqlite3.

However, if you look in the control directory of each, you'll find that php5-sqlite has a proper postinstallation script, whereas php5-sqlite3 does not.

A regular expression within php5-sqlite's postinstallation script looks like it would match pdo_sqlite3.so in addition to the shared objects it was intended to match.

The problem, thus, seems to be that php5-sqlite3 copies the proper files to their proper locations, but does not register them in php.ini; when php5-sqlite is installed, its postinstallation script does so not only for its own drivers, but for php5-sqlite3's as well.

Looking inside the Hardy packages, they exhibit the same issue.

I don't know if this is a Debian issue or an Ubuntu issue, but in any case, unless I am completely off-base here, _a_maintainer_ needs to add a postinstallation script to php5-sqlite3.

Revision history for this message
Dan Bishop (danbishop) wrote :

Thanks Brian! I tried installing php5-sqlite and sure enough I can now use sqlite3 exactly as intended.

Changed in php-sqlite3:
status: New → Confirmed
Revision history for this message
Karoly Negyesi (karoly) wrote :

This is indeed very confusing. The php5-sqlite3 package is IMO a PECL extension which provides sqlite3_* commands which practically noone uses because it's PECL. The mainstream PDO::SQLite driver comes from php5-sqlite but the only hint that will happen is the fact that it depends on some sqlite3 package... some renames IMO in order.

Revision history for this message
Valeri Velkov (tholpoocte) wrote :

There is no bug, because there is no such thing as PDO::SQlite3
You can use the string sqlite as a DSN for the PDO driver, as in
$dbHandle = new PDO('sqlite:test-sqlite3.db');

which opens a connection to a sqlite3 database.
The PDO sqlite dirver supports both sqlite2 and sqlite3 and is installed by the package php-sqlite.
To connect to a sqlite2 database, you would use
$dbHandle = new PDO('sqlite2:test-sqlite2.db');

The package php-sqlite3 installs the PECL SQLite3 extension,which is a completely different animal.
It is used as follows:
$dbHandle = new SQLite3('test.db');

Revision history for this message
mrfelton (tkp) wrote :

how come php5-sqlite3 is not available for intrepid?

Revision history for this message
Brian Hysell (briandh) wrote :

@Valeri Velkov

I'm aware, and was at the time of filing this bug, that you address an SQLite3 database using simply "sqlite" in the DSN.

That said, the descriptions of both php5-sqlite and php5-sqlite3 make it non-obvious which installs PDO support for SQLite3. Given unhelpful descriptions and those names, which package might you expect to give you a PDO driver that supports SQLite3?

Anyway, this appears to simply be a "bug" in the package descriptions, but those sorts of things need every bit as much attention as do software bugs.

Revision history for this message
exactt (giesbert) wrote :

@mrfelton
according to https://launchpad.net/ubuntu/+source/php-sqlite3/ php-sqlite3 was "superseded by php5-sqlite".

Revision history for this message
Jamie Arseneault (spoom) wrote :

FYI, until this package is fixed, you can relatively easily compile the SQLite3 extension from source using the instructions given at http://ubuntuforums.org/showthread.php?t=891767#5 .

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.