We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38970
    • 59 Posts
    I am having an issue with this code, I have verified the outputted sql is returning a row but xpdo/modx is returning false for both. any thoughts on how I can debug this.
    <?php
    //'tracker'
    
    $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/tracker/';
    $modx->addPackage('tracker',$base_path.'model/','');
    $modx->setDebug(true);
    
    $c = $modx->newQuery('LogAccess');
    
    $c->where(
        "ip_addr = '92.20.1.34'"
    );
    
    
    $c->select(array('id'));
    $c->limit(1);
    $stmt = $c->prepare();
    var_dump($stmt);
    
    echo $c->toSQL();
    $l = $stmt->execute();
    var_dump($l);
    //$stmt->execute();
    echo $stmt->queryString;
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    var_dump($row);exit;
    
    $stmt->closeCursor();
    return $output;
    

    the output is
    object(PDOStatement)#47 (1) { ["queryString"]=> string(82) "SELECT `id` FROM `log_access` AS `LogAccess` WHERE ip_addr = '92.20.1.34' LIMIT 1 " } 
    
    SELECT `id` FROM `log_access` AS `LogAccess` WHERE ip_addr = '92.20.1.34' LIMIT 1 
    bool(false) 
    SELECT `id` FROM `log_access` AS `LogAccess` WHERE ip_addr = '92.20.1.34' LIMIT 1 
    bool(false)
    
      • 38970
      • 59 Posts
      This is killing me anyone have any insight ?
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        Why don't you just use something like this?

        $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/tracker/';
        $modx->addPackage('tracker',$base_path.'model/','');
         
        $c = $modx->newQuery('LogAccess');
        $c->where(array(
            'ip_addr' => '92.20.1.34',
        ));
        
        $c->select(array('id'));
        $c->limit(1);
        
        /* This bit is just for logging the SQL */
        $c->prepare();
        echo $c->toSQL();
        
        /* Get the object */
        $object = $modx->getObject('LogAccess', $c);
        var_dump($object->toArray());
        
        return 'Done';
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 38970
          • 59 Posts
          Thanks mark ill give that a try, what is the quickest way to run an update on that row, need to set visited = 1.
            • 38970
            • 59 Posts
            I just tried the code mark and I received this :
            Fatal error: Call to a member function toArray() on a non-object in /home/testdomain.com/public_html/core/cache/includes/elements/modsnippet/24.include.cache.php on line 24
            
              • 3749
              • 24,544 Posts
              That's telling you that the getObject() call failed.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 38970
                • 59 Posts
                He guys,

                Thats what I dont understand the query that is being outputted is pulling a row from the database, but xpdo does not seem to be pullling anything. [ed. note: datarecall last edited this post 13 years, 10 months ago.]
                  • 6038
                  • 228 Posts
                  Have you double-checked you are actually getting any data from that query by copy/pasting the generated SQL statement into a db client (eg phpmyadmin).
                  At least then you can eliminate the possibility of the query not being correct, or that data is not being returned as expected at the db level.
                    • 4172
                    • 5,888 Posts
                    whats your xml-schema of this package?
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!