PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

PHP: 62 characters to see all MySQL queries

Note: This article was originally published at Planet PHP on 15 October 2010.
Planet PHP

Did you ever want to see the database queries an arbitrary PHP MySQL application runs? It takes two free downloads and 62 characters to see them.

  • Get PHP 5.3.4-dev
  • Get PECL/mysqlnd_qc
  • Add 19 characters to your configure line: --enable-mysqlnd-qc
  • Add 43 characters at the end of applications source, e.g. using the auto_append_file configuration setting: var_dump(mysqlnd_qc_get_query_trace_log());
  • Start your query analysis

array(329) { [0]= array(8) { ["query"]= string(27) "SET @@session.sql_mode = """ ["origin"]= string(1330) "#0 /home/nixnutz/Downloads/oxid/core/adodblite/adodbSQL_drivers/mysql/mysql_driver.inc(352): mysql_query('SET @@session.s...', Resource id #26) #1 /home/nixnutz/Downloads/oxid/core/adodblite/adodb.inc.php(316): mysql_driver_ADOConnection-do_query('SET @@session.s...', -1, -1, false) #2 /home/nixnutz/Downloads/oxid/core/oxdb.php(216): ADOConnection-Execute('SET @@session.s...') #3 /home/nixnutz/Downloads/oxid/core/oxconfig.php(479): oxDb::getDb() #4 /home/nixnutz/Downloads/oxid/core/oxconfig.php(406): oxConfig-_loadVarsFromDb('oxbaseshop') #5 /home/nixnutz/Downloads/oxid/core/oxconfig.php(448): oxConfig-init() #6 /home/nixnutz/Downloads/oxid/core/oxsupercfg.php(115): oxConfig::getInstance() #7 /home/nixnutz/Downloads/oxid/core/oxutilsobject.php(207): oxSuperCfg-getConfig() #8 /home/nixnutz/Downloads/oxid/core/oxutilsobject.php(109): oxUtilsObject-getClassName('oxutilsobject') #9 /home/nixnutz/Downloads/oxid/core/oxutilsobject.php(74): oxUtilsObject-oxNew('oxUtilsObject') #10 /home/nixnutz/Downloads/oxid/core/oxfunctions.php(284): oxUtilsObject::getInstance() #11 /home/nixnutz/Downloads/oxid/core/oxutils.php(101): oxNew('oxUtils') #12 /home/nixnutz/Downloads/oxid/core/oxfunctions.php(448): oxUtils::getInstance() #13 /home/nixnutz/Downloads/oxid/index.php(72): require_once('/home/nixnutz/D...') #14 {main}" ["run_time"]= int(0) ["store_time"]= int(0) ["eligible_for_caching"]= bool(false) ["no_table"]= bool(false) ["was_added"]= bool(false) ["was_already_in_cache"]= bool(false) } ... }

If you want to know more, check this presentation.