pdo - SQLite Insert or Ignore/Replace with lastInsertID in one statement -
i feel should easy...
i have table this:
create table table_name ( id integer primary key, name text not null, unique (name collate nocase) )
no 2 names same, case insensitive. right have users adding names , this:
insert table_name (name) values ("my name");
and need id of row, easy php pdo's lastinsertid(). want, if user adding name that's in database, nothing added database, still id without having database call. hoping
insert or replace table_name (name) values ("my name");
and have overwrite same data cell , return lastinsertid (even though wasn't inserted?). doesn't work. other options? have separate database query see if name
field exists?
with or replace clause, statement deletes old row.
just use 2 statements. (there no technical reason doing in single statement.)
Comments
Post a Comment