Skip to content

PHP sqlite3 won't load this extension whereas sqlite3 CLI loads fine #71

@victorgveloso

Description

@victorgveloso

Minimal replication instructions:

/Dockerfile

FROM php:8-apache
RUN apt-get update && apt-get install -y sqlite3 libsqlite3-dev && rm -rf /var/lib/apt/lists/*
COPY src/ /var/www/html/
COPY ini/php.ini /usr/local/etc/php/conf.d/php.ini

/ini/php.ini

sqlite3.extension_dir = /var/www/html/sqlitehash

/src/test.php

<?php
$db = new SQLite3(':memory:');
$db->loadExtension('libsqlite_hashes');
echo $db->querySingle("SELECT hex(sha256('oi'))");

Running

$ mkdir -p /src/sqlitehash/ && cd /src/sqlitehash/
$ wget https://github.com/nyurik/sqlite-hashes/releases/download/v0.9.0/sqlite-hashes-x86_64-unknown-linux-gnu.tar.gz
$ tar -xzvf sqlite-hashes-x86_64-unknown-linux-gnu.tar.gz

Results in the file
/src/sqlitehash/libsqlite_hashes.so is RELEASE 9.0

Running the following command should result in the error as demonstrated:

$ php test.php

Warning: SQLite3::loadExtension(): Unable to load extension at '/var/www/html/sqlitehash/libsqlite_hashes' in /var/www/html/test.php on line 3
php -i | grep sqlite3.extension_dir
sqlite3.extension_dir => /var/www/html/sqlitehash

However, when I run sqlite3 CLI, it just works.

$ cd /var/www/html/sqlitehash && sqlite3
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .load ./libsqlite_hashes
sqlite> SELECT sha256('oi')
   ...> ;
��3cLİ/b��e
)���*
     �A�%�w-�
Xԉ
sqlite> SELECT hex(sha256('oi'));
87F633634CC4B02F628685651F0A29B7BFA22A0BD841F725C6772DD00A58D489

Any help would be much appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions