[PHP-DB] mysql_insert_id - link_identifier

2002-01-28 Thread B. Verbeek

Hello,

How do I use the linkidentifier to get me the last_inserted_id
(mysql_insert_id) from a auto_increment-colomn?

Do I use:

  $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);


$sqllink_id must be the inserted value for the auto-increment-colomn named
orders_id and is placed in var $orders_id


Can anyone tell me if this is correct and what can be done to optimize?


regards
Bart



-- 
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-DB] mysql_insert_id - link_identifier

2002-01-28 Thread B. Verbeek



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?

regards
Bart


-Oorspronkelijk bericht-
Van: Alberto. Sartori [mailto:[EMAIL PROTECTED]]
Verzonden: maandag 28 januari 2002 13:11
Aan: [EMAIL PROTECTED]
Onderwerp: R: [PHP-DB] mysql_insert_id - link_identifier


Run the query without the value of the primary-key field.

-Messaggio originale-
Da: B. Verbeek [mailto:[EMAIL PROTECTED]]
Inviato: lunedì 28 gennaio 2002 13.08
A: Alberto. Sartori
Oggetto: RE: [PHP-DB] mysql_insert_id - link_identifier


? How do you mean ?
regards

-Oorspronkelijk bericht-
Van: Alberto. Sartori [mailto:[EMAIL PROTECTED]]
Verzonden: maandag 28 januari 2002 12:35
Aan: [EMAIL PROTECTED]
Onderwerp: R: [PHP-DB] mysql_insert_id - link_identifier


You can omit the primary key if the filed have auto-increment type

-Messaggio originale-
Da: B. Verbeek [mailto:[EMAIL PROTECTED]]
Inviato: lunedì 28 gennaio 2002 12.29
A: Php-Db-Help (E-mail)
Oggetto: [PHP-DB] mysql_insert_id - link_identifier


Hello,

How do I use the linkidentifier to get me the last_inserted_id
(mysql_insert_id) from a auto_increment-colomn?

Do I use:

  $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);


$sqllink_id must be the inserted value for the auto-increment-colomn named
orders_id and is placed in var $orders_id


Can anyone tell me if this is correct and what can be done to optimize?


regards
Bart



--
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]




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]