Cannot load a custom Virtual Table using PHP
(1) By anonymous on 2020-05-25 14:17:35 [link]
<?php $db = new SQLite3(':memory:'); $rs = $db->query('SELECT sqlite_version()'); while ($row = $rs->fetchArray()) print "<h3>SQLite version: $row</h3>"; $db->query("SELECT load_extension('cvtab.dll','sqlite3_cvtab_init');"); //Attempting to load this way errors as follows: //Warning: SQLite3::query(): not authorized in C:\DL\PHP\QTests.php on line 8 $db->loadExtension('cvtab.dll'); //Attempting to load this way errors as follows: //Warning: SQLite3::loadExtension(): Unable to load extension at //'ext\cvtab.dll' in C:\DL\PHP\QTests.php on line 11 ?> The custom VT loads perfectly fine using the latest windows CLI downloaded from the SQLite website and using and an old sqlite version 3-8-1 20131017 CLI. The PHP SQLite version reported by the version query in the script is: 126.96.36.199, The one bundled with PHP 5.6.40, unfortunately none of the newer PHPs work on stock windows 8.1. Both PHP (php-5.6.40-nts-Win32-VC11-x86.zip) and the custom VT dll are 32 bit, not sure if thread safety in the custom dll will cause this failure... I have the PHP built-in development server running under command prompt as Administrator. php.ini have both these enabled/set: extension=php_sqlite3.dll sqlite3.extension_dir = "ext" "ext\cvtab.dll" does exist. Any pointers MUCH appreciated!!!
(2) By Stephan Beal (stephan) on 2020-05-25 14:23:53 in reply to 1 [link]
> Any pointers MUCH appreciated!!! You've already answered your own question: > The custom VT loads perfectly fine using the latest windows CLI downloaded from the SQLite website and using and an old sqlite version 3-8-1 20131017 CLI. Ergo, the problem is related to the PHP binding and you'll need to ask the PHP people for a solution. (The "not authorized" warning suggests that your PHP build (or configuration) does not permit loading modules, and the PHP folks will be able to say how to remedy that.) This particular project is only responsible for the sqlite C library, the CLI app, and a small handful of closely-related code, not the hundred+ third-party bindings such as those produced by the PHP team.
(3) By Larry Brasfield (LarryBrasfield) on 2020-05-25 14:58:42 in reply to 1 [link]
A recent change in SQLite3 altered the default for whether loading extensions via SQL function load\_extension() is allowed. See the 5th paragraph of section 2 of [Run-time Loadable Extensions](https://sqlite.org/loadext.html). Enabling extension loading has to be done via the C API as mentioned there. As Mr. Beal suggests, a PHP support forum is more apropos for how to proceed. There may be a way to access the sqlite3\_db\_config() API from PHP, and if there is, such a forum would more likely include somebody who knows about that.
(4) By tom (younique) on 2020-05-25 17:23:56 in reply to 1 [link]
I had the same problem about a year ago. I ended up in comiling PHP from source using the latest SQLite and with permission to call "SELECT load_extension".
(5) By John Gelm (gelmjw) on 2020-05-26 17:29:57 in reply to 1 [link]
#load_extensions use in php.ini: [sqlite3] sqlite3.extension_dir = /usr/lib/x86_64-linux-gnu enable_dl = On Then in php program $db->loadExtension('libsqlitefunctions.so');
(6) By anonymous on 2020-05-27 09:39:23 in reply to 5
Still the same errors with both ways. And caling $db->lastErrorCode() and $db->lastErrorMsg() just says: 101 unknown error Not sure if it is windows error just being forwarded or a true PHP one. Calling this way $db->query("SELECT load_extension('cvtab.dll','sqlite3_cvtab_init');"); allows specifying the non default entry point name as 2nd parameter, not sure if that might be the problem with $db->loadExtension('cvtab.dll'); ... Thanks for mentioning enable_dl, didn't know about it!! And to the other responses also as I suspect it will definately help with the hurdles as I go!
(7) By anonymous on 2020-05-28 13:18:31 in reply to 6 [link]
In case someone else end up here... what I think I have figured out this far (Windows only): In php.ini [sqlite3] section set sqlite3.extension_dir to EXACTLY what windows reports as the full path to the extension directory, eg, if extension_dir is set to "ext", ie. the default, then: [sqlite3] sqlite3.extension_dir=C:\DL\PHP\5.6.40\ext\ I then renamed the custom virtual table dll to it's init procedure name as SQLite can pick it up from the nname, for example: Ren custom_vt.dll to initprocname.dll PHP/SQLite will then try to load it and use "sqlite3_initprocname_init" as init procedure, however I now receive Warning: SQLite3::loadExtension(): The specified procedure could not be found. in C:\DL\PHP\DocRoot\LPKQTests.php on line 42 But from the source I can see that it must have came up to the point of loading the custom extension dll...