title: PDO fetch failure on multi line query
body: <p>I think I'm having a fundamental confusion in how PDO works. I have this semi-complicated multiline query that inserts a row into the DB, but I need the id (<code>aid</code>) of the insert after it's finished. I have similar code for another function that works perfectly fine, but this one is not returning anything. I get a result of <code>null</code>. When I execute the same thing in phpmyadmin (replacing params with test values), I get the expected <code>aid</code> back as a result. What am I doing wrong?</p>
  
  <pre><code>function add_list_activity($activity, $lid, $db) 
  {
    $data = array();
  
    $query = " 
        INSERT INTO activities
        (`name`) VALUES (:activity);
  
        SET @act_id = LAST_INSERT_ID();
  
        INSERT INTO lists_activities 
        (`aid`, `lid`) VALUES (@act_id, :lid);
  
        SELECT aid FROM activities WHERE aid = @act_id;
    "; 
  
    // The parameter values 
    $query_params = array( 
        ':activity' =&gt; $activity,
        ':lid' =&gt; $lid
    ); 
  
    try 
    { 
        $stmt = $db-&gt;prepare($query); 
        $result = $stmt-&gt;execute($query_params); 
    } 
    catch(PDOException $ex) 
    {  
        die("Failed to run query: " . $ex-&gt;getMessage()); 
    }
    $data = $stmt-&gt;fetch();
  
    return $data;
  }
  </code></pre>
  
  <p>Thanks!</p>