We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18409
    • 54 Posts
    I don’t know if this is a bug or what but when I do:

    [tt] $datesTableName = $modx->getTableName(’amcCalDates’);
    $sql = "SELECT date FROM $datesTableName where event_id=:event_id";
    $query = new xPDOCriteria($modx, $sql, array(’event_id’=>$_GET[’event_id’]));
    $dates = $modx->getCollection(’amcCalDates’,$query);[/tt]
    I get:
    [tt]Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 261900 bytes) in xpdoobject.class.php on line 866[/tt]

    But if I do:
    [tt] $datesTableName = $modx->getTableName(’amcCalDates’);
    $sql = "SELECT * FROM $datesTableName where event_id=:event_id";
    $query = new xPDOCriteria($modx, $sql, array(’event_id’=>$_GET[’event_id’]));
    $dates = $modx->getCollection(’amcCalDates’,$query);[/tt]
    I get the correct response. Note the change from date to * in the $sql.

    Both queries work fine in phpMyAdmin. This is on Revo 2.0.0-pl using XAMPP on Windows 7 with php 5.3.0.

    Any thoughts?

    [tt](PS - before someone asks, the reason I’m using XPDOCriteria is because I actually want to do:
    $sql = "SELECT min(date), max(date) FROM $datesTableName where event_id=:event_id";
    which doesn’t work either.
    )[/tt]
      • 28215
      • 4,149 Posts
      You need to select at least the primary key of the object you want to retrieve.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 18409
        • 54 Posts
        ah, thanks!
          • 22303 MODX Staff
          • 10,725 Posts
          Actually, you don’t want an object for that query—what you want is to execute the prepared PDOStatement that xPDOCriteria wraps. e.g.
          <?php
          $query = new xPDOCriteria($modx, $sql, array('event_id'=>$_GET['event_id']));
          $resultSet = array();
          if ($query->stmt && $query->stmt->execute()) {
              $resultSet = $query->stmt->fetchAll(PDO::FETCH_ASSOC);
          }
          if (!empty($resultSet)) {
              // do something with the row( s ) returned from your query...
          }
          


          Once you create your xPDOCriteria, you have a PDOStatement and can use it as you would any PDOStatement.