Re: [PHP-DB] mysql_insert_id - link_identifier

2002-01-28 Thread Jason Wong

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] mysql_insert_id - link_identifier

2002-01-28 Thread B. Verbeek

Thanks Jason,

That was the answer I was looking for! It works like you suggested!!

Thanks
regards,

bart

-Oorspronkelijk bericht-
Van: Jason Wong [mailto:[EMAIL PROTECTED]]
Verzonden: maandag 28 januari 2002 13:52
Aan: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]