lastinsertid

Get the last insert id with doctrine 2?

帅比萌擦擦* 提交于 2019-12-17 22:12:09
问题 How can I get the last insert id with doctrine 2 ORM? I didn't find this in the documentation of doctrine, is this even possible? 回答1: I had to use this after the flush to get the last insert id: $em->persist($user); $em->flush(); $user->getId(); 回答2: You can access the id after calling the persist method of the entity manager. $widgetEntity = new WidgetEntity(); $entityManager->persist($widgetEntity); $entityManager->flush(); $widgetEntity->getId(); You do need to flush in order to get this

How to get last insert Id in SQLite?

点点圈 提交于 2019-12-17 09:51:24
问题 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 回答1: 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

undefined method PDO lastInsertId

别说谁变了你拦得住时间么 提交于 2019-12-13 11:53:59
问题 I have an insert query, and I want to get the ID from the table. I have been searching, and I found lastInsertId() for PDO. When I want to use it, I get PHP errors. This is my code: $db = new database(); $naam = $db->quoteQuery($_POST['naam']); $barcode = $db->quoteQuery($_POST['barcode']); $sql = "INSERT INTO products(name, barcode) VALUES (".$name.",".$barcode.")"; $results = $db->executeQuery($sql); $lastid = $results->lastInsertId(); But this gives an error, this one: Fatal error: Call to

insert_id in Kohana 3

霸气de小男生 提交于 2019-12-12 23:04:58
问题 I'm using Kohana 3 framework with Mysql stored procedures. How can I get id of the last inserted record? Here's the code: class Model_MyModel extends Kohana_Model { public function insertNew($param1, $param2) { $result = $this->_db->query(Database::INSERT, 'CALL insertNew('.$param1.', '.$param2.', false)'; return $result; } ... ... } Documentation says, the query() method returns an array with the last insert id and affected rows number, when executing an insert query. When I call: print_r(

Alternative to “PDO::lastInsertId” / “mysql_insert_id”

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 08:04:45
问题 I always hear that using "lastInsertId" (or mysql_insert_id() if you're not using PDO) is evil. In case of triggers it obviously is, because it could return something that's totally not the last ID that your INSERT created. $DB->exec("INSERT INTO example (column1) VALUES ('test')"); // Usually returns your newly created ID. // However when a TRIGGER inserts into another table with auto-increment: // -> Returns newly created ID of trigger's INSERT $id = $DB->lastInsertId(); What's the

Inserting tuple's elements to database

你离开我真会死。 提交于 2019-12-11 17:59:39
问题 I have a tuple that i wanna store its elements, I'm trying to insert it as following and it gives the following error, what am i doing wrong ? records_to_be_inserted is the tuple that has 8 elements. with self.connection: cur = self.connection.cursor() cur.executemany("INSERT INTO rehberim(names, phone, mobile, email, \ photo, address, note, date) VALUES(?, ?, ?, ?, ?, ?, ?, ?)", self.records_to_be_inserTed) Traceback (most recent call last): File "/home/tayfun/workspace/personal_guide

How to find last inserted id while using pdo transaction?

谁都会走 提交于 2019-12-11 14:54:43
问题 I'm using PDO in my web application. In a part of this application, I need to work with PDO Transactions. I need to know last inserted id of first query and use it in the second query, and then if no problem occurs, I will commit this transaction. The problem I have is that how can I find out last inserted id before transaction commit? This is a sample of my need : $db->beginTransaction(); $stmt1 = "INSERT ..."; // An insert query $q = $db->prepare($stmt1); $q->execute(array()); $last = $db-

retrieve last updated column in mysql

北慕城南 提交于 2019-12-10 12:05:52
问题 I have a MySQL query that goes as follows (using Zend_Db): $sql = $handle->quoteInto("UPDATE board SET rank=rank+1 WHERE post_id=?", $postid); $handle->query($sql); (Rank isn't an auto-incrementing PK). I would like to now retrieve the value of rank without preforming another query. I've tried $handle->lastInsertId(); but it doesn't seem to work , since I didn't use MySQL's natural auto-incrementing method (I can't - rank is the rank of a post. I either ++ or -- it.) Any way to do this with

Using LAST_INSERT_ID() via PHP?

纵饮孤独 提交于 2019-12-08 17:38:25
问题 When I execute the following in the MySQL console, it works fine: INSERT INTO videos (embed_code) VALUES ('test code here'); SELECT LAST_INSERT_ID(); But, when I execute the above queries via PHP, the result is empty. Under the data abstraction, I am using a database access class named DB . This is how I have tried the above queries via PHP: $embedCode = htmlentities($_POST['embed_code']); //Insert video in database **WORKS** DB::query("INSERT INTO videos (embed_code) VALUES ('$embedCode');")

PDO - lastInsertId() for multiple insert query

走远了吗. 提交于 2019-12-06 22:12:06
问题 I can insert 2 pets into a table, and get their lastInsertId() for further processing one at a time (2 queries). I am wondering if there is a way to get two lastInsertIds() and assign them to variables if I am inserting 2 rows in 1 query: $query = "INSERT INTO pets (pet_name) VALUES (':coco'),(':jojo')"; $pet_insert = $dbh->prepare($query); $pet_insert->execute(array(':coco' => $coco,':jojo' => $jojo)); $New_PetID = $dbh->lastInsertId(); Is it possible to get the lastInsertId() for coco and