title: How to install locally an extension in SQLite on a Mac?
body: <p>I've no real knowledge about installing an extension. I'm stuck because I cannot use SQRT in SQLite. </p>
  
  <p>I'm using Laravel on a local machine and I'm working on my PHPunit Tests. In one Test I'm using a query with some heavy math functions. </p>
  
  <p>I get the error: </p>
  
  <pre><code>Caused by
  PDOException: SQLSTATE[HY000]: General error: 1 no such function: SQRT
  </code></pre>
  
  <p>I found out that <a href="https://www.sqlite.org/contrib" rel="nofollow noreferrer">SQLite</a> has an extension called: <strong>extension-functions.c</strong></p>
  
  <p>I downloaded it, but I'm not sure if I did everything correctly (obviously not because it does not work):</p>
  
  <ol>
  <li><p>I downloaded it and used this in my terminal</p>
  
  <pre><code>gcc -fno-common -dynamiclib extension-functions.c -o libsqlitefunctions.dylib
  </code></pre></li>
  <li>It compiled this data: libsqlitefunctions.dylib</li>
  <li>With php --ini if found that my php.ini is located in /usr/local/etc/php/7.1/php.ini</li>
  <li>Now I looked up for sqlite3 and found this commented ;sqlite3.extension_dir =</li>
  <li><p>I changed it to </p>
  
  <pre><code>sqlite3.extension_dir =/usr/local/etc/php/7.1/extension/libsqlitefunctions.dylib
  </code></pre></li>
  <li><p>and created the extension folder and put the dylib file inside</p></li>
  <li><p>I restarted my apache with sudo apachectl restart</p></li>
  <li><p>And tried my Query and still, it fails. What did I do wrong?</p></li>
  </ol>
  
  <p><strong>For future readers</strong> </p>
  
  <p>To use it in Laravel you call it like this:</p>
  
  <pre><code>$pdo = DB::connection()-&gt;getPdo();
  $pdo-&gt;sqliteCreateFunction('SQRT', 'sqrt', 1);
  $pdo-&gt;sqliteCreateFunction('ASIN', 'asin', 1);
  $pdo-&gt;sqliteCreateFunction('SIN', 'sin', 1);
  $pdo-&gt;sqliteCreateFunction('COS', 'cos', 1);
  $pdo-&gt;sqliteCreateFunction('POWER', 'pow', 2);
  $pdo-&gt;sqliteCreateFunction('pi', 'pi', 0);
  </code></pre>