简体   繁体   English

从Ubuntu上的php中加载sqlite扩展(15.04)

[英]load sqlite extension from within php on ubuntu (15.04)

On my Ubuntu 15.04 machine I'm trying to load an sqlite-extension within my php code using the following snippet: 在我的Ubuntu 15.04机器上,我尝试使用以下代码段在我的php代码中加载sqlite扩展名:

<?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. 谁能帮我从Ubuntu 15.04上的php中获得此功能。

Thanx a lot in advance. 非常感谢。

Cheers, D. 干杯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. PS:由于我在以sqlite作为数据库运行phpunit测试时使用此命令,因此我在命令行而不是在Web服务器上下文中运行它。

I did not manage to get it working in Ubuntu 15.04. 我没有设法使其在Ubuntu 15.04中工作。 Upgrading to Ubuntu 16.04 solved the problem. 升级到Ubuntu 16.04可解决此问题。

PS: the default php version on Ubuntu 16.04 is 7.0.x. PS:Ubuntu 16.04的默认php版本是7.0.x。 You might need to install php5.6 if you want to use it. 如果要使用它,可能需要安装php5.6。 See http://www.lornajane.net/posts/2016/php-7-0-and-5-6-on-ubuntu 参见http://www.lornajane.net/posts/2016/php-7-0-and-5-6-on-ubuntu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM