We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4619
    • 23 Posts

    How could check the sql statement executed thru xpdo ?

    Thanks
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: cariboo at Sep 25, 2010, 12:49 PM

      How could check the sql statement executed thru xpdo ?
      <?php
      // define query
      $query = $xpdo->newQuery('myClass', array('food' => 'beer'));
      
      // prepare and dump the SQL to the log
      $query->prepare();
      $xpdo->log(xPDO::LOG_LEVEL_ERROR, $query->toSql());
      ?>
        • 40165
        • 2 Posts
        Hello there,

        we'd like to profile our modx website, to list of the db queries that are made on page refresh.

        is there a way that I can use the above to output 'all' the queries made for a particular page?
        This way I could have a 'query debug' panel on my page for development that gives the queries made, number of queries etc.
        This would be a useful guide for us when caching etc.

        Thanks
        Jim
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          You'd have to do that manually I think.
            • 22303 MODX Staff
            • 10,725 Posts
            At the moment, there is no way (that I am aware of) to catch ALL of the queries executed on the PHP-side via PDO, other than stepping through the PHP application via remote debugging and watching each being executed. If someone else knows how to log all activity for the mysql PDO driver, that would be the best way; I know the SQL Server driver has such a facility, but am not aware of anything like it for mysql.

            For now though, your best bet would be to log the activity on the mysql side. You can get a lot more information and analysis on the queries from the database itself. If you want to profile the PHP application, try xDebug's profiling tool.