We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    I’ve been meaning to ask this for a while. Often times I know what my query statement would look like if I were writing it in straight mySQL... but I’m not entirely certain that I’m building an xPDOQuery object that is equivalent and doing what I want it to. If there was a way to get the equivalent mySQL query from an xPDOQuery object... that would be extremely helpful for debugging. Is there a way to do that?
      • 26903
      • 1,336 Posts
      Without looking I think ther’s an sql() method that returns the actual sql string thats going to go to the database, you see its usage in log output statements.
        Use MODx, or the cat gets it!
        • 21257 MODX Staff
        • 730 Posts
        It’s the ->toSQL() method. From docs: "Converts the current xPDOQuery to parsed SQL".
        $Q = $xpdo->newQuery('People');
        $Q->where(array('floating_in_space'=> 1));
        $sql = $Q->toSQL();
        

          Mike Schell
          Lead Developer, MODX Cloud
          Email: [email protected]
          GitHub: https://github.com/netProphET/
          Twitter: @mkschell
          • 17499 ☆ A M B ☆
          • 872 Posts
          It’s the right method but to view the SQL statement you need to use prepare() method before:

          $Q = $xpdo->newQuery('People');
          $Q->where(array('floating_in_space'=> 1));
          $c->prepare();
          $sql = $Q->toSQL();