note 51945 deleted from function.sqlite-last-insert-rowid by cmb
| From: | cmb@php.net | Date: | Mon, 02 Nov 2020 15:01:01 +0000 |
| Subject: | note 51945 deleted from function.sqlite-last-insert-rowid by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215743@lists.php.net to get a copy of this message | ||
Note Submitter: David
----
I have noticed that this will still return an insert id even if a table has not been assigned a
primary key or has not been assigned a primary key correctly. If the table was not created correctly
sqlite_last_insert_rowid() will return its internal row id, which is probably not what you want. The
correct way to establish a primary key migh look something like this look something like this:
create table some_table (id INTEGER PRIMARY KEY, some_field varchar(10))
Then you can try:
insert into some_table (some_field) values ('bob')
You will see that an id will be automatically generated and
calling sqlite_last_insert_rowid() will return the expected value