Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are four ways to accomplish this depending on what you are using, the last being the much more reliable.</p> <h1><strong>The General Query Log</strong></h1> <p>MySQL provides a mechanism to log just about everything that the <code>mysqld</code> process is doing, via the general query log. As you described in your question you probably do not have persistent connections, so you will need to either:</p> <ul> <li>Enable the MySQL general query log when the <code>mysqld</code> process is started, with the <a href="http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_log" rel="nofollow"><code>--log[=file_name]</code></a> <ul> <li>Set a global/session variable with <code>SET GLOBAL general_log = 'ON'</code>.</li> </ul></li> </ul> <p>Fore more information about the general query log, see the <a href="http://dev.mysql.com/doc/refman/5.1/en/query-log.html" rel="nofollow">MySQL 5.1 reference manual</a>.</p> <h1><strong>Using <code>sed</code> (or manually!)</strong></h1> <p>This technique involves creating a a new function, and renaming all of the <code>mysqli_*</code> function calls to call another function.</p> <p>Presuming your newly created function is named <code>proxy_query()</code>, you can use <code>sed</code> to traverse through all files and change them automatically:</p> <pre><code>sed i '.bck' 's/mysqli_query/proxy_query/' </code></pre> <p>The <code>-i</code> paramater specifies that the file should be edited in place, and that a copy should be made of the original file and have a <code>.bck</code> extension appended.</p> <h1><strong>The <code>runkit</code> extension</strong></h1> <p>I must admit that I'm being naive here, and that I haven't used this particular extension before - but it is possible to rename functions with this PECL extension. The requirements for this extension can be found here, and note that it is <em>not</em> bundled with PHP.</p> <p>As with above, you can create a proxy function where all calls will go through. Let's assume it's also called <code>proxy_query</code>. Usage would go something like this:</p> <pre><code>// rename the function (a very bad idea, really!) runkit_function_renam('mysqli_connect', 'proxy_super'); function mysqli_query($query, $resultmode = MYSQLI_STORE_RESULT) { // do something with the SQL in $query // .. and call mysqli_query, now proxy_super return proxy_super($query, $resultmode); } </code></pre> <p>I have to note here that <strong>this method is highly discouraged</strong>. You shouldn't ever need to set default PHP functions.</p> <h1><strong>Using Pdo/OO-mysqli</strong></h1> <p>This is the simplest technique, and probably the most reliable as well. If you're using Pdo already, you can simply extend the <code>\Pdo</code> class. A similar approach could be used with MySQL Improved(<code>mysqli</code>):</p> <pre><code>class MyPdo extends \Pdo { public function query($query [, ... ]) { // do something with $query return parent::query($query [, ... ]); } } </code></pre> <p>Also note here, that this will only work if you are using Pdo, and if you are able to change the instantiation of the <code>Pdo</code> object, to overwrite it to your own class: <code>MyPdo</code>. For more information about the <code>\Pdo</code> class, and it's children, see the <a href="http://www.php.net/manual/en/book.pdo.php" rel="nofollow">manual</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload