insert-id

mysql_insert_id alternative for postgresql

is there an alternative for mysql_insert_id() php function for PostgreSQL? Most of the frameworks are solving the problem partially by finding the current value of the sequence used in the ID. However, there are times that the primary key is not a serial column.... ...

MySQL ON DUPLICATE KEY - last insert id?

I have the following query: INSERT INTO table (a) VALUES (0) ON DUPLICATE KEY UPDATE a=1 I want the ID of either the insert or the update. Usually I run a second query in order to get this as I believe insert_id() only returns the 'inserted' ID and not the updated ID. Is there a way to INSERT/UPDATE and retrieve the ID of the row wi...

MySQL current_insert_id()? (Not last_insert_id())

Hi All, I am inserting a row with a char column for a hash based on (among other things) the row's auto id. I know I can insert it, fetch the insert_id, calculate the hash, and update it. Does anyone know of a way to do this in a single query? You would need the rows insert_id at the time of insert. Is that completely impossible, ...

Postgresql and PHP: is the currval a efficent way to retrieve the last row inserted id, in a multiuser application?

Hi guys! Im wondering if the way i use to retrieve the id of the last row inserted in a postgresql table is efficent.. It works, obviously, but referencing on the serial sequence currval value could be problematic when i have many users adding rows in the same table at the same time. My actual way is: $pgConnection = pg_connect('host...

Private Messaging System With Threading/Replies

Hello All, I'm currently working on creating a private messaging system, (PHP/MySQL) in which users can send message to multiple recipients at one time, and those users can then decide to reply. Here's what I'm currently working with: tbl_pm tbl: id date_sent title content status ENUM ('unread', 'read') DEFAULT 'unread' tblpm_info t...

Dependency in identity column values after multiple SQL inserts

If the next is right: There are SQL string with multiple inserts (using a stored procedure): "EXEC SPInsertData ... EXEC SPInsertData ... EXEC SPInsertData ..." The id in identity column, which is auto incremented, of every new record is smaller than the id of the next one. E.g. after executing the given SQL string the id of the first...

MySQL: use the id of the row being inserted in the insert statement itself

I'm trying to some something like that: INSERT INTO dir_pictures SET filename=CONCAT(picture_id,'-test'); picture_id is my primary key, auto-increment. Basically I'm trying to put the id of this insert statement, in the statement itself. I'm sure it can be done with some extra PHP code or using more than one statements, but I was won...

How to get the insert ID in JDBC?

I want to INSERT a record in a database (which is Microsoft SQL Server in my case) using JDBC in Java. At the same time, I want to obtain the insert ID. How can I achieve this using JDBC API? ...

What are the better ways with INSERT on relational tables?

I'm experiencing my first mysql INSERT tests and I'm using these tables: table employees -> employee_id -> employee_name -> employee_surname -> employee_url table areas -> area_id -> area_city -> area_address -> area_country table agencies -> agency_id -> agency_name -> agency_url table node_employees -> node_id -> employee_id -> are...

zend framework get last insert id of multi row insert using execute

How would I get the last inserted ID using a multirow insert? Here is my code: $sql='INSERT INTO t (col1, col2, col3) VALUES (1, 2, 3), (4, 5, 6), (7, 8, 9)'; // example $stmt = $contactsTable->getAdapter()->prepare($sql); $stmt->execute(); $rowsAdded=$stmt->rowCount(); // mysql_affected_rows $lastId=$stmt->lastInsertId(); echo '<br>La...

how do i handle concurrent inserts in mysql table and fetch the correct insert id

I am using adodb for PHP library. For fetching the id at which the record is inserted I use this function "$db->Insert_ID()" I want to know if there are multiple and simultaneous inserts into the database table, will this method return me the correct inserted id for each record inserted ? The reason I am asking this is because I use t...

PHP MySQLi and MySQLi_STMT: Which insert_id to use?

Hello all, Both the MySQLi and MySQLi_STMT classes have an $insert_id property. If I am connected to my database using a MySQLi object (say $db), and then I perform an INSERT with a MySQLi_STMT object (say $stmt), to get the id of the last INSERT, should I use: $last_id = $db->insert_id; or $last_id = $stmt->insert_id; Or would ...

Retrieve Core Data Entities in Order of Insertion

Is there an internal ID variable or timestamp I can use in a NSSortDescriptor to retrieve Core Data entities in the order they were inserted? I would rather not have to create such properties if there is a cleaner way, though will obviously do so if there are no other alternatives. ...

Insert date and time into Mysql

Hi..guys I am trying to insert date and time into mysql datetime field. When a user select a date and time, it will generate two POST variables. I have searched internet but still not sure how to do it. My code. //date value is 05/25/2010 //time value is 10:00 $date=$_POST['date']; $time=$_POST['time']; $datetime=$date.$time If...