1

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
Community
  • 1
  • 1
geoB
  • 4,578
  • 5
  • 37
  • 70
  • Why do you want to do it for Windows? If you are developing in Windows - it is better to install virtual machine and do everything in *nix system. It is much easier to compile php modules there. Like this - http://stackoverflow.com/questions/948899/how-to-enable-sqlite3-for-php – Cheery Nov 12 '14 at 00:57
  • @Cheery: Yeah, I've heard that. Already have 2 VMs on my windows box for checking my work. I'm just old school. Besides, that wouldn't solve the problem - pdo_sqlite still won't have soundex(). – geoB Nov 12 '14 at 01:05
  • `pdo_sqlite still won't have soundex()` but, if you recompile it with https://www.sqlite.org/compile.html#soundex Except that you will be dependable on the current install. – Cheery Nov 12 '14 at 01:19
  • @Cheery: I've been to that page. My utter lack of experience with compiling does not get me from those instructions to either a php_pdo_sqlite.dll or a pdo_sqlite.so. Can you point me to something that will close the loop? – geoB Nov 12 '14 at 01:22
  • It looks like you just need to define SQLITE_SOUNDEX. The command-line syntax for that is `/DSQLITE_SOUNDEX`. So you might try something like `cl sqlite3.c /DSQLITE_SOUNDEX -link -dll -out:php_pdo_sqlite.dll`. – Mike Sherrill 'Cat Recall' Nov 13 '14 at 22:27
  • @MikeSherrill'CatRecall' Thank you for this. Unfortunately, after replacing the original dll I get "PHP Startup: Invalid library (maybe not a PHP library) 'php_pdo_sqlite.dll'". So it looks like I'm missing some PHP magic. I'm working with v5.4.25. – geoB Nov 14 '14 at 01:27
  • Read the procedures, answers, and comments for this SO question: http://stackoverflow.com/q/10978020/562459 – Mike Sherrill 'Cat Recall' Nov 14 '14 at 02:31
  • @MikeSherrill'CatRecall' I'm guessing this will give me the same results as I get trying to compile in my Ubuntu 14 VM. I have since learned that the more likely successful path is to build from within the php source code and php extension skeleton, etc. Since that route is less than well documented I'm going to move my development and testing to the Ubuntu VM. Two reasons: one, pdo_sqlite.so includes `soundex()`; two, running the functional test takes 2/3 the time! But I thank you for your contributions. – geoB Nov 14 '14 at 18:11
  • @Cheery Turns out you were right about *nix but for a different reason. As you may read in the above comment, the PHP installed in Ubuntu has a sqlite that includes `soundex()`. That's where I'm moving to. – geoB Nov 14 '14 at 18:14
  • @geoB `compile time option unknown!` it should be something like `-DSQLITE_SOUNDEX` – Cheery Nov 14 '14 at 18:44
  • @Cheery See my quasi-duplicate post [here](http://askubuntu.com/questions/548953/compile-sqlite-with-soundex-feature) for syntax. – geoB Nov 14 '14 at 19:24

1 Answers1

0

How to add the soundex() function to php_pdo_sqlite.dll

The 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 C:\php-sdk\phpdev\vc9\x86\php-5.5.18\ext\pdo_sqlite\config.w32, adding /D SQLITE_SOUNDEX

config.w32 snippet
// $Id$
// vim:ft=javascript

ARG_WITH("pdo-sqlite", "for pdo_sqlite support", "no");

if (PHP_PDO_SQLITE != "no") {
    EXTENSION("pdo_sqlite", "pdo_sqlite.c sqlite_driver.c sqlite_statement.c", null, "/DSQLITE_THREADSAFE=" + (PHP_ZTS == "yes" ? "1" : "0") + " /D SQLITE_ENABLE_FTS3=1 /D SQLITE_ENABLE_COLUMN_METADATA=1 /D SQLITE_CORE=1 /D SQLITE_SOUNDEX /I" + configure_module_dirname + "/../sqlite3/libsqlite /I" + configure_module_dirname);
    
    ADD_EXTENSION_DEP('pdo_sqlite', 'pdo');
    // If pdo_sqlite is static, and sqlite3 is also static, then we don't add a second copy of the sqlite3 libs
    if (PHP_PDO_SQLITE_SHARED || PHP_SQLITE3_SHARED || PHP_SQLITE3 == 'no') {
        ADD_SOURCES(configure_module_dirname + "/../sqlite3/libsqlite", "sqlite3.c", "pdo_sqlite");
    }
}

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 a php_pdo_sqlite.dll with the soundex() function.

Community
  • 1
  • 1
geoB
  • 4,578
  • 5
  • 37
  • 70