faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 6 people (67%) answered Yes
Recently 3 of 5 people (60%) answered Yes

Entry

Has anyone else had any problems with getting mysql_insert_id ($result) return a value using mysql 3.23.21 with Win98 and PHP 4?

Dec 22nd, 2000 12:09
Ben Udall, Bobby Edge, http://www.php.net/manual/function.mysql-insert-id.php


From your question, it would appear that you're using the result from 
the query as a parameter, like this:
$result = mysql_query($query);
$id     = mysql_insert_id($result);
However, the php 3 and 4 documentation says mysql_insert_id() takes a 
link identifier as an optional parameter, not a result identifier.  
Below is an example of how it should be used.
$db_link = mysql_connect();
$result  = mysql_query($query, $db_link);
$id      = mysql_insert_id($db_link);
You can also omit the '$db_link' parameter, and php will use the last 
database connection made, as shown below:
$result = mysql_query($query);
$id     = mysql_insert_id();