RE: [PHP-DB] mysql_insert_id - link_identifier

From: Date: Mon, 28 Jan 2002 13:03:01 +0000
Subject: RE: [PHP-DB] mysql_insert_id - link_identifier
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-16242@lists.php.net to get a copy of this message
Thanks Jason, That was the answer I was looking for! It works like you suggested!! Thanks regards, bart -----Oorspronkelijk bericht----- Van: Jason Wong [mailto:phplist@gremlins.com.hk] Verzonden: maandag 28 januari 2002 13:52 Aan: php-db@lists.php.net Onderwerp: Re: [PHP-DB] mysql_insert_id - link_identifier On Monday 28 January 2002 20:18, B. Verbeek wrote: > I already run the query without the value of the primary-key field: > > $q_orders_id2 = "INSERT INTO orders(orders_datum, orders_sessid)"; > $q_orders_id2.= " VALUES ('$date', '$sid')"; > $r_orders_id2 = mysql_query($q_orders_id2, $sqllink_id); > $orders_id = mysql_insert_id($sqllink_id); > << > > The primary-key field is: "orders_id" (not in above query). > Only "orders_datum" and "orders_sessid" are sent with the query. > > When I call mysql_insert_id with tha vars: "$q_orders_id" or > "$r_orders_id" I get an warning (Warning: Supplied argument > is not a valid MySQL-Link resource in /home/httpd/blabla/file.php > on line 91) but not the wanted id. > > In the manual it says that mysql_insert_id() is used with the > linkidentifier ($sqllink_id ? ) but not how to define the identifier > in mysql_query()... > > >>How do I define a linkidentifier for a specific call to > > mysql_query() and then use mysql_insert_id() with that > linkidentifier of the query? When you initiate the connection to the db using mysql_connect() or mysql_pconnect() it returns a MySQL link identifier. In most cases you do NOT need to specify the link identifier when using mysql_query(). If you're only dealing with one database throughout your script then there's no reason for you to specify the link identifier because PHP automatically uses the most recently used one. That is it automatically chooses the correct link identifier to use. So in your case what you want would probably be something like this: $q_orders_id2 = "INSERT INTO orders(orders_datum, orders_sessid)"; $q_orders_id2 .= " VALUES ('$date', '$sid')"; # for debugging, you may want to echo $q_order_id2 $r_orders_id2 = mysql_query($q_orders_id2); $orders_id = mysql_insert_id(); hth -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* I used to be Snow White, but I drifted. -- Mae West */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#16242) next »