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

    I've been struggling with the code below. I got is from this page "https://forums.modx.com/thread/35321/querying-a-non-modx-table-in-revolution", but i can't get it to work.

    I also tried changing PDO::FETCH_ASSOC into PDO_FETCH_ASSOC

    I hope someone can tell me what i'm doing wrong.

    $sql =  'SELECT * FROM orders ORDER BY created DESC LIMIT 1';
    
    $stmt = $modx->prepare($sql);
    $stmt->execute(); 
    
    // Put data in array
    $order_data = $stmt->fetch(PDO::FETCH_ASSOC);
    if ($order_data == '') {
        return 'Resultset empty for user '. $user_id.'.<br />'.$sql;
    } else {
        return 'Data found!';
    }