Attempts to build a functional test where soundex() is required fail due to the fact that the function by default is not compiled in pdo_sqlite. Functional tests are being built using LiipFunctionalTestBundle.
The error reported is:
PDOException: SQLSTATE[HY000]: General error: 1 no such function: Soundex
and the SQLite documentation says:
The soundex(X) function ... is omitted from SQLite by default
I've tried (from php docs) $db->sqliteCreateFunction('soundex', 'sqlite_soundex', 1);
where
function sqlite_soundex($string)
{
return soundex($string);
}
but get
...sqlite_soundex is not callable...
So, how to compile a version of Windows php_pdo_sqlite.dll
? (SQLite docs show how to compile a "plain" sqlite.dll.) Or is there a better solution?
Edit - with MS Visual Studio 12 Express, compile time option unknown!
>cl sqlite3.c -SQLITE_SOUNDEX -link -dll -out:php_pdo_sqlite.dll
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
cl : Command line warning D9002 : ignoring unknown option '-SQLITE_SOUNDEX'
sqlite3.c
Microsoft (R) Incremental Linker Version 11.00.50727.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:sqlite3.exe
-dll
-out:php_pdo_sqlite.dll
sqlite3.obj
How to add the
soundex()
function to php_pdo_sqlite.dllThe following is an adaptation of the instructions Build your own PHP on Windows. I used Visual Studio 12 Express for Desktop & PHP 5.5 source code from windows.php.net.
Proceed per instructions up to extracting source code into the tree. At that point I modified
config.w32 snippetC:\php-sdk\phpdev\vc9\x86\php-5.5.18\ext\pdo_sqlite\config.w32
, adding/D SQLITE_SOUNDEX
Step 14:
configure --disable-all --enable-cli --enable-pdo --with-pdo-sqlite=shared
Step 15:
nmake php_pdo_sqlite.dll
The result was a php_pdo_sqlite.dll in the ...\Release_TS directory
I needed to update my PHP installation from 5.4 to 5.5 and tested. The original sqlite dll caused the soundex() error. The replacement dll allowed the test to pass. SUCCESS!
EDIT - for PHP 7.0.0
After several failed attempts, changing Step 14 above to
configure --disable-all --enable-pdo --with-pdo-sqlite=shared --enable-apache2-4handler
allowed creation of aphp_pdo_sqlite.dll
with thesoundex()
function.