douyuan1752 2019-07-07 00:49
浏览 226
已采纳

为PHP启用sqlite3 FTS5

I'm trying to use SQLite3 FTS5 (full-text search) with PHP on CentOS.. but I couldn't get it successfully after so much time trying.

I'm building a loadable FTS5 Extension for SQlite and tried the following steps (from docs)

in the server terminal (SSH) :

$ yum install libsqlite3x-devel
$ wget -c http://www.sqlite.org/src/tarball/SQLite-trunk.tgz?uuid=trunk -O SQLite-trunk.tgz
$ tar -xzf SQLite-trunk.tgz
$ cd SQLite-trunk
$ ./configure && make fts5.c
$ gcc -g -fPIC -shared fts5.c -o fts5.so

But I'm having the following error in the last step:

fts5_index.c:732:11: error: ‘SQLITE_PREPARE_PERSISTENT’ undeclared (first use in this function)
fts5_index.c:732:37: error: ‘SQLITE_PREPARE_NO_VTAB’ undeclared (first use in this function)
fts5_main.c:888:29: error: ‘SQLITE_PREPARE_PERSISTENT’ undeclared (first use in this function)
fts5_main.c:1029:31: error: ‘SQLITE_PREPARE_PERSISTENT’ undeclared (first use in this function)
fts5_storage.c:139:15: error: ‘SQLITE_PREPARE_PERSISTENT’ undeclared (first use in this function)
fts5_storage.c:140:41: error: ‘SQLITE_PREPARE_NO_VTAB’ undeclared (first use in this function)

The file fts5.so is not produced so I can't use it in the server

So do you have any idea how to fix this error and produce fts5.so file successfully

  • 写回答

1条回答 默认 最新

  • doublel83422 2019-07-07 00:49
    关注

    I found that I have to generate header files before the last step

    so the full steps looks like this:

    $ yum install libsqlite3x-devel
    $ wget -c http://www.sqlite.org/src/tarball/SQLite-trunk.tgz?uuid=trunk -O SQLite-trunk.tgz
    $ tar -xzf SQLite-trunk.tgz
    $ cd SQLite-trunk
    $ ./configure
    $ make fts5.c sqlite3.h sqlite3ext.h
    $ gcc -g -fPIC -shared fts5.c -o fts5.so
    

    Then I had to load the fts5.so as loadable extension for sqlite

    1- Copy the fts5.so file to a new folder on server /sqlite_ext

    $ mkdir /sqlite_ext
    $ cp fts5.so /sqlite_ext
    

    2- Edit sqlite3.extension_dir in php.ini to point to the same folder like this

    sqlite3.extension_dir = "/sqlite_ext"
    

    3- Then in my php file, load the extension :

    $db->loadExtension('fts5.so');
    

    Update :

    It's better to update server's SQLite as a whole with --enable-fts5 option

    $ wget -c https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
    $ tar -xzf sqlite-autoconf-3280000.tar.gz
    $ cd sqlite-autoconf-3280000
    $ ./configure --enable-fts5 --prefix=/usr --disable-static CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_ENABLE_UNLOCK_NOTIFY=1 -DSQLITE_SECURE_DELETE=1 -DSQLITE_SOUNDEX"
    $ make
    $ make install
    

    Now the latest SQLite is installed for the server but not for PHP, let's do it for PHP

    $ mv aclocal.m4 config.m4
    $ phpize
    

    Check for your SQLite version in server using $ sqlite3 --version and in PHP using phpinfo();

    *notice: the link mentioned in the first step is for the latest sqlite-autoconf amalgamation at the time of this answer. there maybe a more recent version for you . check here

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 调用函数时,无关变量的改变引起函数值的改变
  • ¥15 xy坐标转化为经纬度坐标
  • ¥15 一般三角模糊数的上界值和下届值取中值的多少比较合理?
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥20 Hbase启动失败,无法启动HMaster
  • ¥15 sqpingboot在父模块已经引入了mybatisplus 在子组件不写版本号还是报错
  • ¥20 Lumerical FDTD solutions 中模型的相对阻抗,有效介电常数和有效磁导率的实部和虚部的数据如何获得?
  • ¥100 sql reporting service 远程smtp服务器配置支持
  • ¥15 ppyoloe_r带角度目标检测,loss_cls没法收敛
  • ¥15 淘宝交易指数如何解读,其关联的数据指标是什么