Questions tagged [lastinsertid]

135 questions
0
votes
1 answer

get ids of all inserted records by last query executed in cakephp

I can find the primary key id of last inserted record as follows: $this->Model->save($record); $id = $this->Model->getLastInsertId(); I am looking for something like this: $this->Model->saveAll($records); $ids = $this->Model->getLastInsertIds(); I…
pMan
  • 7,118
  • 10
  • 29
  • 34
0
votes
6 answers

What could cause duplicate ids on a auto increment primary key field (mysql)?

RESOLVED From the developer: the problem was that a previous version of the code was still writing to the table which used manual ids instead of the auto increment. Note to self: always check for other possible locations where the table is written…
Darryl Hein
  • 134,677
  • 87
  • 206
  • 257
0
votes
0 answers

Pass lastInsertId() in variable

I get the last insertid with pdo in object1.php: object1.php class 1234{ public function test{ $query = "INSERT INTO " . $this->table_name . " SET uid=:uid, order_id=:order_id, position=:position, optionindex=:optionindex,…
Marco
  • 131
  • 1
  • 8
0
votes
3 answers

How to get last inserted ID and send again

How can I send the lastInsertId again to another php document? Explanation why: After someone sends a form (form.html) to a database (send.php) he will get an ID for that form. This ID I show in the send.php to the person via PDO:

Your ID:

Jessy642
  • 23
  • 6
0
votes
1 answer

PDO postgresql last inserted id return 'false' or -1

I have code $dbh = new PDO("pgsql:host=localhost; port=5432; dbname=gpd; user=postgres; password=postgres"); $sth = $dbh->prepare("INSERT INTO res (res_name, res_order) VALUES ('London', 1)"); $sth->execute(); $id = $dbh->lastInsertId(); echo…
0
votes
2 answers

mysql : Any command to use instead of mysql_insert_id(); in PHP?

I want to get primarykey ID of just insert item. In PHP has mysql_insert_id(). I write in C#
Prince OfThief
  • 6,075
  • 13
  • 38
  • 52
0
votes
1 answer

PDO lastinsertId is returning 0 in a transaction, php - 5.6

I have a method written in PHP PDO (5.6) that should return the last inserted id. The issue is that the insertion is accomplished but it returns 0 "string". There is a lot of posts here in stackoverflow with the same issue, but I could not find a…
zwitterion
  • 3,958
  • 9
  • 43
  • 64
0
votes
1 answer

Subsonic 3.0.0.4 active record templates for mysql not returning last inserted id

Steps to reproduce error: CREATE TABLE person ( person_id int(11) NOT NULL AUTO_INCREMENT, firstname varchar(20) DEFAULT NULL, lastname varchar(20) DEFAULT NULL, age int(11) DEFAULT '0', PRIMARY KEY (person_id) ) ENGINE=InnoDB AUTO_INCREMENT=36…
0
votes
1 answer

Java, PreparedStatement, TransactSQL (MS SQL), last insert id

I insert some values into a database using a PreparedStatement, but it seems, that i cannot retrieve the last insert id in that case. I try to use the same statement as i use for Statements (below) but it doent work. It says, that .executeQuery()…
Ibolit
  • 8,071
  • 5
  • 46
  • 76
0
votes
1 answer

Display recent data after button is clicked(different page)

I have a modal that adds a project to database. When I clicked the add button I want the recent project data to appear on a pop-up window after the modal has been closed. I think it is all about the LAST_INSERT_ID() function but it does not work.…
0
votes
0 answers

Inserting values with a foreign key relationship into two different tables simultaneously? (MySQL)

So I have 2 tables: users with columns id (primary, auto_increment), username, password, person_id (foreign key) people with columns id (primary, auto_increment), first_name, last_name What I'm trying to do is when registering a new account have a…
0
votes
3 answers

PHPMYADMIN LAST_INSERT_ID returns 0

I have problem with LAST_INSERT_ID. CREATE TABLE for_test( id_test INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, test_name VARCHAR(30) ); INSERT INTO for_test (test_name) VALUES ('test1'); INSERT INTO for_test (test_name) VALUES ('test2'); I added…
Petrus
  • 201
  • 1
  • 3
  • 14
0
votes
2 answers

Getting last id PDO

This is what i have: $stmt = $handler->prepare('SELECT id FROM users'); $stmt->execute(); $id = $handler->lastInsertId(); echo $id; So, i want result to be for example "There is $id registered users".
Monk
  • 67
  • 9
0
votes
0 answers

LastInserID from other table insert to table

how i can select lastinserid from table player and insert into to test_table? $stmt = $pdo->prepare("INSERT INTO baza.test_table (`player`) VALUES (?)"); $a = mt_rand(1, 100); $stmt->bindParam(1, $a, PDO::PARAM_INT); $stmt->execute(); …
Raven
  • 13
  • 4
0
votes
3 answers

Was: Grab the last inserted id - mysql Now: Where should we call the last insert id?

Here's the thing, I don't have access to code that inserts data into a given table. However, I need to add related additional data into another table. So, I was thinking about grabbing the last inserted ID and from there... insert the related data…
MEM
  • 27,721
  • 40
  • 115
  • 190
1 2 3
8 9