We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2249
    • 60 Posts
    ashfinlayson Reply #1, 15 years ago
    Hi, sorry if this has been covered elsewhere, I have looked but cant find anything on this that i actually comprehend.

    $modx->db->insert etc is no longer available, thats fine but how do i do it in revo?

    I tried this but with no success:

    $sql = "INSERT INTO pfu_industries (title,display) VALUES ($industry,0)";
    $stmt = $this->modx->prepare($sql);
    return $stmt->execute();

    this works fine for a select query though once i added:

    return $stmt->FetchAll(PDO::FETCH_ASSOC);

    Any help would be REALLY appreciated, deadline is tomorrow sad

    Cheers
    Ash
      • 22303 MODX Staff
      • 10,725 Posts
      See PDO::exec() for INSERT/UPDATE/DELETE queries — all PDO functions are available directly from the xPDO (or MODX) class.
        • 2249
        • 60 Posts
        ashfinlayson Reply #3, 15 years ago
        Thanks opengeek,

        I realise now that i just forgot the quotes around the fields sad

        This works and is returning a Boolean, do you know if/how i can return the id of the item that has just been inserted ?

        $sql = "INSERT INTO pfu_industries (title, display) VALUES ('$industry', '0')";
        $stmt = $this->modx->prepare($sql);
        return $stmt->execute();


        Cheers!
        Ash
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: ashfinlayson at Oct 17, 2011, 08:41 AM

          This works and is returning a Boolean, do you know if/how i can return the id of the item that has just been inserted ?

          http://php.net/manual/en/pdo.lastinsertid.php
            • 2249
            • 60 Posts
            ashfinlayson Reply #5, 15 years ago
            Thanks, your a hero