Advanced usage: SQLite3::lastInsertRowID() and SQLite3::querySingle()

int SQLite3::lastInsertRowID ()

mixed SQLite3::querySingle ( string query [, bool entire_row = false ])

There are two extra methods for SQLite that you are likely to find helpful. Firstly, the equivalent function of mysqli_insert_id() is lastInsertRowID(), and is a method on your open database connection. Remember that creating auto-incrementing fields in SQLite requires you to declare them as "INTEGER PRIMARY KEY" - the AUTO_INCREMENT keyword is not required. lastInsertRowID() will return the auto-increment ID number that was used for the last INSERT query you sent.

Secondly, the querySingle() method lets you execute an SQL query and get back the first column of the first row of the result of your query, which makes it extremely convenient for quick queries. If you set the second parameter to querySingle() to be true, then you get back an array of all the values that represent the first row of the result.

 

Next chapter: Mixing SQLite and PHP: SQLite3::createFunction() >>

Previous chapter: Getting started with SQLite 3

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.