lastinsertid

PDO lastInsertId() always return 0

情到浓时终转凉″ 提交于 2019-11-28 02:41:52
问题 I've come across with a problem. My framework was working just fine with PHP 5.3.0. I upgraded my PHP version to PHP 5.4.x and I started to have few issues with some parts of my framework. After PHP version upgrade, PDO lastInsterId() always returns 0 . I have auto-increment field called id . It is adding the data to database without any problems. For some reason I keep getting 0 as last insert id. Here is my code; databaseobjects.php public static function create () { global $db; $attributes

mysql getting last_insert_id() in a trigger

北城以北 提交于 2019-11-27 22:58:57
It's my understanding that when you call last_insert_id() it goes by connections, so you'll get the id of the last row inserted on the same connection where last_insert_id() is called, right? So what if I call last_insert_id() in an 'AFTER INSERT' trigger? What I want to do is basically this DELIMITER $$ CREATE TRIGGER sometrigger AFTER INSERT ON sometable BEGIN INSERT INTO anothertable (id, lastup) VALUES (last_insert_id(), NOW()); END $$ It's very important that the id in 'anothertable' is the same as in 'sometable' Would this work or should I create a stored procedure instead that inserts

Mysql mulitple row insert-select statement with last_insert_id()

荒凉一梦 提交于 2019-11-27 15:15:01
问题 Ok. So the short of it is, I was trying to do an INSERT SELECT such as: START TRANSACTION; INSERT INTO dbNEW.entity (commonName, surname) SELECT namefirst, namelast FROM dbOLD.user; SET @key = LAST_INSERT_ID(); INSERT INTO dbNEW.user (userID, entityID, other) SELECT user_id, @key, other FROM dbOLD.user; COMMIT; Of course @key does not return each subsequent LAST_INSERT_ID() from each insert but the ID from only the last insert. Basically, I'm splitting an old USER Table into an ENTITY and

How to get last insert Id in SQLite?

大兔子大兔子 提交于 2019-11-27 09:03:08
Is there any built in function available in SQLite to fetch last inserted row id. For eg :- In mysql we have LAST_INSERT_ID() this kind of a function. For sqllite any function available for doing the same process. Please help me. Thanks SQLite This is available using the SQLite last_insert_rowid() function : The last_insert_rowid() function returns the ROWID of the last row insert from the database connection which invoked the function. The last_insert_rowid() SQL function is a wrapper around the sqlite3_last_insert_rowid() C/C++ interface function. PHP The PHP version/binding of this function

PDO lastInsertId issues, php

好久不见. 提交于 2019-11-27 07:45:54
问题 I have tried lots of ways to get the last inserted ID with the code below (snipplet from larger class) and now I have given up. Does anyone know howto get PDO lastInsertId to work? Thanks in advance. $sql = "INSERT INTO auth (surname, forename, email, mobile, mobilepin, actlink, regdate) VALUES (:surname, :forename, :email, :mobile, :mobpin, :actlink, NOW())"; $stmt = $this->dbh->prepare($sql); if(!$stmt) { return "st"; } $stmt->bindParam(':surname', $this->surname); $stmt->bindParam('

lastInsertId does not work in Postgresql

▼魔方 西西 提交于 2019-11-27 06:51:03
问题 I am using Postgresql, when I want to use PDO to retrieve the latest insertion ID, I got a problem. Here is my code: $db->lastInsertId('columnName'); The error message says SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "columnName" does not exist I guess I have some misunderstanding about "sequence object" stated in the PHP Manual. Note: Returns the ID of the last inserted row, or the last value from a sequence object, depending on the underlying driver. For example, PDO_PGSQL()

mysql getting last_insert_id() in a trigger

前提是你 提交于 2019-11-26 21:15:12
问题 It's my understanding that when you call last_insert_id() it goes by connections, so you'll get the id of the last row inserted on the same connection where last_insert_id() is called, right? So what if I call last_insert_id() in an 'AFTER INSERT' trigger? What I want to do is basically this DELIMITER $$ CREATE TRIGGER sometrigger AFTER INSERT ON sometable BEGIN INSERT INTO anothertable (id, lastup) VALUES (last_insert_id(), NOW()); END $$ It's very important that the id in 'anothertable' is

What happens when auto_increment on integer column reaches the max_value in databases?

半腔热情 提交于 2019-11-26 19:22:00
问题 I am implementing a database application and I will use both JavaDB and MySQL as database. I have an ID column in my tables that has integer as type and I use the databases auto_increment-function for the value. But what happens when I get more than 2 (or 4) billion posts and integer is not enough? Is the integer overflowed and continues or is an exception thrown that I can handle? Yes, I could change to long as datatype, but how do I check when that is needed? And I think there is problem

How to program a MySQL trigger to insert row into another table?

 ̄綄美尐妖づ 提交于 2019-11-26 15:22:57
I'm looking to create a MySQL trigger on a table. Essentially, I'm creating an activity stream and need to log actions by users. When a user makes a comment, I want a database trigger on that table to fire and: Grab the ID of the last inserted row (the id of the comment row). perform an INSERT into an activities table, using data from the last inserted row. I'll essentially replicate this trigger for deleting comments. Questions I had: Is LAST_INSERT_ID() the best way to grab the id? How do I properly store the data from the last inserted comment row for use in my "INSERT into activities"

mysqli last insert id

好久不见. 提交于 2019-11-26 11:56:29
I would like to associate the image with firstname, lastname...how can I retrieve the last rowand use it to insert to the other table? I tried $image = $mysqli->insert_id; then binding but it doesn't work. Can someone help me out? $image = $mysqli->insert_id;//this should come from table2 $stmt = $mysqli->prepare(" insert into table1 (username, firstname, lastname, image) select ?,?,?,image from table2 t2 where username = ? and t2.id = ? "); $stmt->bind_param('sssss', $username, $fname, $lname, $username, $image); $stmt->execute(); Abdallah Alhabarneh mysqli::$insert_id -- mysqli_insert_id —