0

On my Ubuntu 15.04 machine I'm trying to load an sqlite-extension within my php code using the following snippet:

<?php #content of test.php
$db = new SQLite3(':memory:');
$db->query("SELECT load_extension('/dir/to/sqlite/extension/libsqlitefunctions.so');");
$resultSet = $db->query("SELECT asin(1) as a;");

But I always get the following error message:

PHP Warning:  SQLite3::query(): not authorized in /my/dir/test.php on line 3
PHP Stack trace:
PHP   1. {main}() /my/dir/test.php:0
PHP   2. SQLite3->query() /my/dir/test.php:3
PHP Warning:  SQLite3::query(): Unable to prepare statement: 1, no such function: asin in /my/dir/test.php on line 4
PHP Stack trace:
PHP   1. {main}() /my/dir/test.php:0
PHP   2. SQLite3->query() /my/dir/test.php:4

Loading the same extension from the command line works fine:

$sqlite3
SQLite version 3.8.7.4 2014-12-09 01:34:36
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> SELECT load_extension('/dir/to/sqlite/extension/libsqlitefunctions.so');
sqlite> SELECT ASIN(1) as a;
1.5707963267949

See this question on how to get this to work.

Can anyone help me get this working from within php on Ubuntu 15.04.

Thanx a lot in advance.

Cheers, D.

PS: as I use this when running phpunit tests with sqlite as database, I run it on the command line and not in a web-server context.

Community
  • 1
  • 1
Dominik
  • 141
  • 1
  • 3
  • 14
  • What user id does your web server (running PHP) run under? Does this id have different permissions on the libsqlitefunctions.so file than your own user id? – BareNakedCoder May 18 '16 at 22:12
  • I run the php script on the command line to get the output mentioned above as the web-server is configured not to show these kinds of errors. The extension file has 777 as permission and is owned by the same user that runs the script. "$php test.php" – Dominik May 19 '16 at 07:10
  • When I change the error-reporting in php and run the script through the web-server, I get the same errors. – Dominik May 19 '16 at 07:16

1 Answers1

0

I did not manage to get it working in Ubuntu 15.04. Upgrading to Ubuntu 16.04 solved the problem.

PS: the default php version on Ubuntu 16.04 is 7.0.x. You might need to install php5.6 if you want to use it. See http://www.lornajane.net/posts/2016/php-7-0-and-5-6-on-ubuntu

Dominik
  • 141
  • 1
  • 3
  • 14