how to get last inserted id - zend

Posted by Lemon on Stack Overflow See other posts from Stack Overflow or by Lemon
Published on 2011-01-07T10:17:14Z Indexed on 2011/01/13 11:53 UTC
Read the original article Hit count: 311

Filed under:
|

I'm trying to get latest inserted id from a table using this code:

$id = $tbl->fetchAll (array('public=1'), 'id desc');

but it's always returning "1"

any ideas?


update: I've just discovered toArray();, which retrieves all the data from fetchAll. The problem is, I only need the ID. My current code looks like this:

$rowsetArray = $id->toArray();
$rowCount = 1;

foreach ($rowsetArray as $rowArray) {
    foreach ($rowArray as $column => $value) {
       if ($column="id") {$myid[$brr] = $value;}
      //echo"\n$myid[$brr]";
    }
    ++$rowCount;
    ++$brr;
}

Obviously, I've got the if ($column="id") {$myid[$brr] = $value;} thing wrong. Can anyone point me in the right direction?

An aternative would be to filter ID's from fetchAll. Is that possible?

© Stack Overflow or respective owner

Related posts about sql

Related posts about zend-framework