Questions tagged [last-insert-id]

LAST_INSERT_ID is MySQL specific functionality to get the value of the AUTO_INCREMENT column most recently inserted into. It is the recommended means of getting the value in MySQL, because SELECT MAX(auto_increment) ... is not reliable, as concurrency problems can occur.

LAST_INSERT_ID is MySQL specific functionality to get the value of the AUTO_INCREMENT column most recently inserted into. It is the recommended means of getting the value in MySQL, because SELECT MAX(auto_increment) ... is not reliable, as concurrency problems can occur.

That said, this functionality is not ANSI. Sequences are now ANSI, supported by DB2, Oracle, PostgreSQL, and SQL Server "Denali"). The ANSI equivalent to LAST_INSERT_ID would be: CURRVAL ( NEXTVAL is used to get the next value).

Documentation:

215 questions
0
votes
3 answers

Qt's odbc driver does not support LastInsertId with mysql, whats the workaround?

Im using Qt 4.8.3 and the MySQL ODBC 3.51 Driver. The driver does not seem to support LastInsertId which I test like this: db.driver()->hasFeature(QSqlDriver::LastInsertId) I need it to find the auto increment id I just inserted query.exec("INSERT…
odinthenerd
  • 5,422
  • 1
  • 32
  • 61
0
votes
1 answer

Using select last_insert_id to generate unique ids

After reading through possible options here on Stackoverflow, I don't see an answer for the exact case I'm considering... CASE: I have a php system that auto-generates mysql-connected templates. In order for the system to work, I need each…
Soyo
  • 141
  • 2
  • 11
0
votes
3 answers

Return latest insert id

I can't get latest insert id. This is my php code: $query='INSERT INTO candidates (company_id, name, surname, address1, address2, city, county, postcode, cv, skills, distance) VALUES (10254, \'name\', \'surname\', \'1st Floor\', \'Street\',…
miszczu
  • 1,179
  • 4
  • 19
  • 39
0
votes
1 answer

Problems with multiple mySQL inserts

I'm building a simple cms and I'm trying to automatically create an additional in the database when a user signs up. The code worked just fine, with the first insert line, but once I added a second one, it stopped working. I got this code structure…
Richard
  • 209
  • 2
  • 10
0
votes
1 answer

Get all insert ids in a transaction

I have two tables in a MySQL database: "messages" and "message_tags". The "messages" table has an auto increment column "message_id". In Java I want to add a batch of messages to the database using the java.sql package. I want to do this in one…
Thomas
  • 10,289
  • 13
  • 39
  • 55
0
votes
2 answers

Perl and MySQL - Return a field from last row of a table using DBI possibly with last_insert_id?

I am trying to return a members firstname field from the table users from the last row of users. my $dbh = DBI->connect($dsn, $db_user_name, $db_password) or die "$DBI::errstr"; my $LastID = $dbh->last_insert_id(`firstname`); ##but I want from…
Jim_Bo
  • 317
  • 5
  • 17
-1
votes
1 answer

Nesting LAST_INSERT_ID() in a PDO prepared statement?

Using PHP with MySQL and PDO prepared statements, I would like to mimic an opaque id in a simple, safe and efficient way. The idea is to add a random value to the current value of LAST_INSERT_ID. INSERT INTO table SET id = LAST_INSERT_ID(…
nil_s
  • 32
  • 4
-1
votes
1 answer

insert many rows, LAST_INSERT_ID return 1

Have: 1. create DB 2. create Table 3. insert 3 rows 4. select LAST_INSERT_ID() Here test code: DROP DATABASE IF EXISTS TEST; CREATE DATABASE TEST; USE TEST; CREATE TABLE test ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, age INT …
Vitaly Fadeev
  • 886
  • 10
  • 13
-1
votes
1 answer

Cannot access php mysqli connection object property

I have a connection class and it connects to the desired db table successfully. I have performed an insert query and i want to get the last inserted id of the connection. But I get a Notice: Undefined property: connection::$insert_id error. I…
guitarlass
  • 1,587
  • 7
  • 21
  • 45
-1
votes
1 answer

Get the id of the last saved entry

Save gives only true or false. $query = (new Item())->fill([ 'first'=>$first, 'second'=>$second ])->save(); $lastInsertId = $query->id; //does not work... return ['status'=>true];
-1
votes
1 answer

LastInsertId is returning 0, when using database/sql package with oracle driver

I am using database/sql package with oracle driver (“gopkg.in/rana/ora.v4”), when I am inserting the data, it’s LastInsertId Method is returning 0, while data is successfully inserted. Attaching code. package main import ( “database/sql” …
-1
votes
2 answers

PHP MYSQL Select Last Inserted ID

I tried to find an answer on here already, as well as read the PHP doc on it, however it doesn't explain it very well. I'm just trying to get the last ID inserted by the user. I know MYSQL is deprecated, but I need to do it this way. This is what I…
hashtagbad
  • 97
  • 11
-1
votes
3 answers

PHP registration form including the database

While I refresh my browser the entries of the registration form goes into the Database every time i press REFRESH, Professor told me to resolve this problem with the help of LAST_INSERT_ID(). I am able to get the last_insert_id from the database but…
-1
votes
2 answers

cakephp save is not working 2.X

I am using CakePHP 2.3, I want to save data as follows follows: $insertUser = array( 'Name' => $Name, 'LastName' => $lastName, 'password' => $password, 'email' => $email, 'TimeStamp' => $presentTime, 'RefererUserId' =>…
user123456
  • 95
  • 2
  • 15
-1
votes
2 answers

Php Pdo - Selecting last inserted

i have a 'insert into' and 'select' querys together in one query. $_SESSION['LoginUID']=1; $Mesaj='ffdd'; $Ek=12; $cid=112; $Kaydet=$db->query(" Insert Into Reply (Kimden,Mesaj,Ek,cid) Values…
traBolics
  • 89
  • 1
  • 3
  • 13
1 2 3
14
15