2

I am using latest OS X El Capitan. My MAMP is 3.5 PRO. I am running PHP 7.0.0 in it. You can see the info of the PHP here.

I figured that SQLite is available in OS X by default. But the version of this SQLite in OS X was 3.8. JSON1 extension is only available in SQLite since the version 3.9.

So first, I tried to upgrade this. I downloaded precompiled binaries (3.12.1) for OS X and replace the sqlite3 file in /etc/bin/ folder. I thought It was done because I check the console with running /usr/bin/sqlite3 directly. You can see the result below. The version is upgraded to the latest version.

enter image description here

Then I tried to check the SQLite version in PHP.

<blockquote>
    <?php print_r(SQLite3::version()); ?>
</blockquote>

Unfortunately It said;

Array ( [versionString] => 3.8.10.2 [versionNumber] => 3008010 )

Then I stuck at this point. Where can I look next?

Update

I succesfully installed the SQLite 3.12.1 via homebrew.

brew install sqlite3 --with-json1 --with-ft5

And now I can run json functions in console. But still can't connect the API via PHP.

<?php
    $db  = new SQLite3("sqlite");

    $sql = "create table user(name,phone);";
    //$db->query("SELECT load_extension('myextension.so');");
    $sql = 'insert into user (name, phone) values("oz", json(\'{"cell":"+491765", "home":"+498973"}\'));';
    $db->exec($sql);
?>

Warning: SQLite3::exec(): no such function: json in /Users/Fehmi/Data/root/sqlite/info.php on line 17

fozuse
  • 754
  • 2
  • 11
  • 29
  • 1
    I don't know OSX but you'll probably need to get a `php_sqlite3.so` of that version and put in the extensions dir. You might be out of luck if it's not included with PHP 7. – AbraCadaver Apr 11 '16 at 21:57
  • 1
    Do not go replacing system binaries; unless you've seriously compromised your OS security, it shouldn't even be possible. You've installed a binary version of PHP that was compiled against a certain version of SQLite, and nothing you do can change that. I'd suggest installing via MacPorts or brew. – miken32 Apr 11 '16 at 22:57
  • @miken32 Thanks, you are right! I did backup before replacing the file and now I switched back to default one and update SQLite with `sudo port install sqlite3`. In console, everything is as expected but PHP still gives me `3.8.10.2` – fozuse Apr 11 '16 at 23:17
  • 1
    This "MAMP" PHP is compiled against that version of SQLite and nothing you do will change that. You need to get rid of it and install everything from MacPorts. – miken32 Apr 11 '16 at 23:27

0 Answers0