note 22749 deleted from function.mysql-connect by betz
| From: | betz@php.net | Date: | Sun, 02 Oct 2005 16:59:56 +0000 |
| Subject: | note 22749 deleted from function.mysql-connect by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96191@lists.php.net to get a copy of this message | ||
Note Submitter: ideservefreesoftware at gmx dot de
----
If you use mysql_connect with identical parameters twice (e.g. a second connection to log all sql
queries without an impact on the first one), the resource variables will be different (echo $dbl
says Resource id #1, echo $dbl_log says Resource id #2), but in some way the same
(mysql_insert_id($dbl) and mysql_insert_id($dbl_log) are always identical).
Workaround for those using PHP < 4.2.0 (4.2.0 provides the new_link parameter to solve this
problem):
use a separate db-user for the second connection
I encountered this problem with PHP Version 4.0.6.
Example:
$dbl = @mysql_connect($dbms_hn, $dbms_un, $dbms_pw);
$dbl_log = @mysql_connect($dbms_hn, dbms_un, $dbms_pw);
mysql_select_db($dbms_db, $dbl);
mysql_select_db($dbms_db, $dbl_log);
$sql = ... insert into table-1-with-autoincrement-column statement;
$rs = mysql_query($sql, $dbl);
echo "dbl: " . $dbl . " insert_id: " . mysql_insert_id($dbl) .
'<br/>';
echo "dbl_log: " . $dbl_log . " insert_id: " . mysql_insert_id($dbl_log) .
'<br/>';
$sql = ... insert into table-2-with-autoincrement-column statement;
$rs = mysql_query($sql, $dbl_log);
echo "dbl: " . $dbl . " insert_id: " . mysql_insert_id($dbl) .
'<br/>';
echo "dbl_log: " . $dbl_log . " insert_id: " . mysql_insert_id($dbl_log) .
'<br/>';
Result: (table1 initially contained 3 rows)
dbl: Resource id #1 mysql_insert_id: 4
dbl_log: Resource id #2 mysql_insert_id: 4
dbl: Resource id #1 mysql_insert_id: 1
dbl_log: Resource id #2 mysql_insert_id: 1
This should be the result:
dbl: Resource id #1 mysql_insert_id: 4
dbl_log: Resource id #2 mysql_insert_id: 0
dbl: Resource id #1 mysql_insert_id: 4
dbl_log: Resource id #2 mysql_insert_id: 1
---