how to get last inserted Id of a Sqlite database using Zend_Db

后端 未结 5 859
-上瘾入骨i
-上瘾入骨i 2021-01-13 08:55

I\'m trying to fetch the last inserted row Id of a Sqlite DB in my PHP application. I\'m using Zend Framework\'s PDO Sqlite adapter for database handling. the lastInsertId()

5条回答
  •  抹茶落季
    2021-01-13 09:24

    Do not use

    SELECT * FROM tablename WHERE id = (SELECT COUNT(*) FROM tablename);
    

    instead use

    SELECT MAX(id) as id FROM tablename LIMIT 1;
    

    or

    SELECT id FROM tablename ORDER DESC LIMIT 1;
    

提交回复
热议问题