How to load sqlite extension in PDO?

Firstly, I want to report a case in order to avoid misunderstandings.

For the sqlite extension, I mention the Sqlite extension, such as FTS, and not the PHP sqlite extension.

I use PDO Sqlite in my application, it cannot be changed.

As I saw here , Sqlite extensions can be downloaded as a request, presented below:

SELECT load_extension('xyz.so'); $db = new PDO ( 'sqlite:qwert.db' ); $db->query("SELECT load_extension('myextension.so');"); $db->query("SELECT myfunction(name) FROM table"); $rows = $db->fetchAll(PDO::FETCH_CLASS, 'stdClass'); 

Note: myfunction - myextension method

But when I test this request from PDO, it returns an unauthorized message.

For testing purposes, I tried the PHP Sqlite3 extension to load the extension using the code below:

 $db = new SQLite3('qwer.db'); $db->loadExtension('xyz.so'); 

Working

As I know, PDO Sqlite does not have a method like loadExtension for loading extensions

Any idea how I can handle this?

+7
source share
1 answer

the compiler flag could not be found, and we solved it with a hacked hack in the pdo_sqlite extension. fixed sqlite_driver.c with sqlite3_enable_load_extension () from sqlite3 API.

 --- 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); } 

Hope this helps ...

+6
source

All Articles