Questions tagged [lastinsertid]

135 questions
0
votes
1 answer

PDO::lastInsertID returning 0

After reading and trying almost every answer on this subject lastInsertId still returns 0. I think I might be overlooking something quite obvious, but can't seem to find what. This is my code: public function create($ordertype, $userid, $travel,…
MartijnICU
  • 430
  • 6
  • 22
0
votes
1 answer

Last_insert_id returns 0 for autoincremented column with letters and numbers

I used a trigger to generate id: ug01, ug02... I want to insert them into the foreign key column but last_insert_id() returns 0 creating an error. How can I get the value of the "last_insert_id" as it is in the primary key column.
Beulah Ana
  • 301
  • 2
  • 14
0
votes
1 answer

Access lastInsertId variable outside a function

so I have a simple code here that will insert a data and will return the last inserted id. Here is my code: function newUser($fname, $age) { global $newUserLastID; $conn = new PDO('mysql:host=localhost;dbname=myDB', 'root', ''); …
wobsoriano
  • 8,501
  • 19
  • 63
  • 125
0
votes
1 answer

PHP OOP - Returning lastInsertId from two functions

I'm new to OOP and have a question regarding functions returning something with the same variable name, for example below: class CompanyManager { function createCompany() { // PDO - create the company return $db->lastInsertId(); …
Loop77
  • 88
  • 6
0
votes
1 answer

Mysql 5.0 LAST_INSERT_ID() differs after upgrading to 5.6

Migrating from MySQL 5.0 to 5.6 i noticed that the INSERT_LAST_ID() function behaves different when using inside a trigger. My simplified situation: Table A has a (after insert) trigger: insert into table_B (ID) values(LAST_INSERT_ID()); Table B has…
0
votes
4 answers

php retrieving id of the last record inserted and insert it in another table

I'm trying to retrieve the id of the last record inserted in the table 'authors' and insert the retrieved id in the 'articles' table; here's my code: $title = mysql_real_escape_string($_POST[title]); $body =…
Mauro74
  • 4,274
  • 13
  • 50
  • 75
0
votes
1 answer

How to get last inserted id in SQL Server 2000 using ODBC?

I'm using this code to insert new record to database: function newProtocol($date, $type, $text, $who, $reff) { $sql = "INSERT INTO c_rozhovor (ref_kunde, protokol_typ, besuch_protokol, datum_vzniku, kto_vytvoril) VALUES ('" …
Incredible
  • 1,335
  • 3
  • 18
  • 39
0
votes
1 answer

Weird insert behavior with mysql and codeginiter

I have a fairly simple insert statement <...> if (!empty($attributes)) { $sql = 'INSERT INTO `part_attrs` (`part_id`, `attr`, `type`, `list_order`) VALUES (?, ?, ?, ?)'; foreach($attributes as $key => $attribute) { …
Ian Burris
  • 5,779
  • 17
  • 55
  • 80
0
votes
1 answer

Invalid Argument to getUInt64 when retrieving LAST_INSERT_ID()

I have added a record to my table which auto-increments the primary key. I am having no luck retrieving this new value. The MySQL documents say to use the SELECT LAST_INSERT_ID(); in a query. I have done this, but can't retrieve the results. …
Thomas Matthews
  • 52,985
  • 12
  • 85
  • 144
0
votes
2 answers

lastInsertId() returns 0

I have looked through the similar questions here but have not been able to solve my problem…all help is greatly appreciated! Basically, I have the following SQL code in my PHP: $query = 'CREATE TEMPORARY TABLE tmp SELECT * from orders WHERE…
Jo.P
  • 1,029
  • 4
  • 13
  • 31
0
votes
1 answer

PDO: lastInsertId what value return?

in PHP if I use $last_id = $db->lastInsertId(); The variable $last_id does will get the value of the last row I've inserted in that instance or the latest row of the entire db? if there are many users that connect and update database at the same…
JB.
  • 83
  • 9
0
votes
2 answers

VBA How to find last insert id?

I have this code: With shtControleblad Dim strsql_basis As String strsql_basis = "INSERT INTO is_calculatie (offerte_id) VALUES ('" & Sheets("controleblad").Range("D1").Value & "')" rs.Open strsql_basis, oConn, adOpenDynamic,…
Muiter
  • 41
  • 1
  • 1
  • 4
0
votes
2 answers

how to get array of latest auto incremented id's?

One single Query to insert multiple rows : $My query = "INSERT INTO exp_channel_titles(channel_id,author_id,ip_address) VALUES(11,1,'203.109.119.2'),(11,1,'203.109.119.2'),(11,1,'203.109.119.2')"; What I want : array of auto incremented id. what…
HIRA THAKUR
  • 15,044
  • 14
  • 47
  • 82
0
votes
1 answer

MySQL LAST_INSERT_ID() with INSERT INTO tablea SELECT FROM tableb

Is it possible to update the source table with the LAST_INSERT_ID from the target table? INSERT INTO `target` SELECT `a`, `b` FROM `source` The target table has an auto increment key id which I would like to store in the source table for further…
remy
  • 1,413
  • 10
  • 14
0
votes
1 answer

How to get last inserted id in zf2?

I am new in zf2. I make a create action and want to get last inserted id but calender_id always equal to zero. How can I get the last insert id in create action ? Here is my code: public function createAction() { if…
Arsal Ali
  • 958
  • 3
  • 20
  • 53
1 2 3
8
9