How to get last insert Id in SQLite?

SQLite This is available using the SQLite last_insert_rowid() function: The last_insert_rowid() function returns the ROWID of the last row insert from the database connection which invoked the function. The last_insert_rowid() SQL function is a wrapper around the sqlite3_last_insert_rowid() C/C++ interface function. PHP The PHP version/binding of this function is sqlite_last_insert_rowid(): Returns the rowid of the … Read more

PDO lastInsertId() always return 0

Other than a bug in php/PDO or your framework, there are two possibilities. Either lastInsertId() is called on a different MySQL connection than the insert, or you are generating the id in your application/framework and inserting it, rather than letting auto_increment generate it for you. Which column in the table is the primary key/auto_increment? Is … Read more

How to program a MySQL trigger to insert row into another table?

drop table if exists comments; create table comments ( comment_id int unsigned not null auto_increment primary key, user_id int unsigned not null ) engine=innodb; drop table if exists activities; create table activities ( activity_id int unsigned not null auto_increment primary key, comment_id int unsigned not null, user_id int unsigned not null ) engine=innodb; delimiter # … Read more

mysqli last insert id

mysqli::$insert_id — mysqli_insert_id — Returns the auto generated id used in the last query, Example: $mysqli = new mysqli(“localhost”, “my_user”, “my_password”, “world”); /* check connection */ if (mysqli_connect_errno()) { printf(“Connect failed: %s\n”, mysqli_connect_error()); exit(); } $mysqli->query(“CREATE TABLE myCity LIKE City”); $query = “INSERT INTO myCity VALUES (NULL, ‘Stuttgart’, ‘DEU’, ‘Stuttgart’, 617000)”; $mysqli->query($query); printf (“New Record … Read more