php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64810 impossible to load extension via pdo_sqlite
Submitted: 2013-05-10 07:38 UTC Modified: 2016-08-29 14:31 UTC
Votes:24
Avg. Score:4.8 ± 0.5
Reproduced:23 of 23 (100.0%)
Same Version:12 (52.2%)
Same OS:15 (65.2%)
From: kamatoz at gmail dot com Assigned:
Status: Open Package: PDO SQLite
PHP Version: Irrelevant OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-05-10 07:38 UTC] kamatoz at gmail dot com
Description:
------------
Currently if you use php pdo_sqlite it's impossible to load an sqlite extension 
to sqlite. It's good practice to turn off this opportunity by default, but it 
should be possible to override the behavior via config file

Test script:
---------------
$pdo = new PDO('sqlite:test.db','','',[PDO::ATTR_ERRMODE=> PDO::ERRMODE_EXCEPTION]);

try {
    $result = $pdo->query('select load_extension("libspatialite.so.3")');
}
catch (PDOException $e) {
    echo "Failed to get DB handle: " . $e->getMessage() . "\n";
    exit;
}

Expected result:
----------------
No exception should be thrown

Actual result:
--------------
Failed to get DB handle: SQLSTATE[HY000]: General error: 1 not authorized


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-23 18:14 UTC] jwhite at tdc-group dot com
Very much need this too.  Would it be possible, if this is disabled for security concerns, to offer a flag in the php.ini to enable this feature?

I'm not sure how helpful this is, but someone has hacked their own copy of php to allow the load_extension function to work with PDO.

http://stackoverflow.com/questions/8756146/how-to-load-sqlite-extension-in-pdo

--- php-5.3.7.old/ext/pdo_sqlite/sqlite_driver.c    2012-01-06 11:04:44.000000000 -0500
+++ sqlite_driver.c 2012-01-06 08:16:58.000000000 -0500
@@ -718,6 +718,8 @@
        goto cleanup;
    }

+   sqlite3_enable_load_extension(H->db, 1);
+
    if (PG(safe_mode) || (PG(open_basedir) && *PG(open_basedir))) {
        sqlite3_set_authorizer(H->db, authorizer, NULL);
    }
 [2014-09-17 14:55 UTC] benjamin dot morel at gmail dot com
+1
Definitely a show-stopper!
 [2016-05-18 21:23 UTC] bugs dot php dot net at businger dot ch
+1: please make this a php.ini option
 [2016-08-29 14:31 UTC] cmb@php.net
-Package: PDO related +Package: PDO SQLite
 [2018-04-25 04:52 UTC] zach at zachlanich dot com
+1 This is a huge problem for us Laravel users who need Spatial Calculation. I've spent days trying to find a work-around for my unit tests. My whole suite runs unbearably slow due to needing to use an actual MySQL database for most tests. It's currently not possible/probable to use the raw SQLite3 php class instead of PDO in Laravel, nor would it be practical to attempt to do so. Ability to override via config would be huge for us.
 [2018-07-05 02:03 UTC] cwt137 at gmail dot com
Hello. I submitted a PR for this. The unit test still fail. If someone knows the PHP internals, can they please have a look at this? https://github.com/php/php-src/pull/3368
 [2018-10-30 14:50 UTC] cwt137 at gmail dot com
Hello,

I fixed all the issues with this PR. Please check it out and comment on it.
 [2018-12-21 15:20 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Implemented request #64810 (impossible to load extension via pdo_sqlite)
On GitHub:  https://github.com/php/php-src/pull/3368
Patch:      https://github.com/php/php-src/pull/3368.patch
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Nov 16 21:01:32 2019 UTC