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

    I am having a problem using getCollection. It appears it is trying to execute the prepared statement before it replaces the question marks with the values. Here is my code:

    $rundatetime = date('Y-m-d H:i:s');
    $c = $modx->newQuery('modCronjob');
    $c->where(array(
    	'nextrun:=' => null,
    	'OR:nextrun:<=' => $rundatetime,
    	'AND:active:=' => true,
    ));
    $c->prepare();
    $log = print_r($c->toSql(), true); $modx->log(modX::LOG_LEVEL_ERROR, __FILE__.' line '.__LINE__.' To SQL-->'.$log.'<--');
    $cronjobs = $modx->getCollection('modCronjob', $c);
    


    and here is what I get in the error log:


    [2013-05-28 03:25:02] (ERROR) /var/www/future/public_html/assets/components/cronmanager/cron.php line 24 $cronjobs-->SELECT `modCronjob`.`id` AS `modCronjob_id`, `modCronjob`.`snippet` AS `modCronjob_snippet`, `modCronjob`.`properties` AS `modCronjob_properties`, `modCronjob`.`minutes` AS `modCronjob_minutes`, `modCronjob`.`lastrun` AS `modCronjob_lastrun`, `modCronjob`.`nextrun` AS `modCronjob_nextrun`, `modCronjob`.`sortorder` AS `modCronjob_sortorder`, `modCronjob`.`active` AS `modCronjob_active` FROM `modx_cronjobs` AS `modCronjob` WHERE ( `modCronjob`.`nextrun` IS NULL OR `modCronjob`.`nextrun` <= '2013-05-28 03:25:02' AND `modCronjob`.`active` = 1 ) <--
    [2013-05-28 03:25:02] (ERROR) Error preparing statement for query: SELECT `modCronjob`.`id` AS `modCronjob_id`, `modCronjob`.`snippet` AS `modCronjob_snippet`, `modCronjob`.`properties` AS `modCronjob_properties`, `modCronjob`.`minutes` AS `modCronjob_minutes`, `modCronjob`.`lastrun` AS `modCronjob_lastrun`, `modCronjob`.`nextrun` AS `modCronjob_nextrun`, `modCronjob`.`sortorder` AS `modCronjob_sortorder`, `modCronjob`.`active` AS `modCronjob_active` FROM `modx_cronjobs` AS `modCronjob` WHERE ( `modCronjob`.`nextrun` IS ? OR `modCronjob`.`nextrun` <= ? AND `modCronjob`.`active` = ? ) - Array
    (
    [0] => 42000
    [1] => 1064
    [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? OR `modCronjob`.`nextrun` <= ? AND `modCronjob`.`active` = ? )' at line 1
    )

    How do I get those question marks replaced with the values?