NYCPHP Meetup

NYPHP.org

[nycphp-talk] OO & database connections

Chris Snyder csnyder at chxo.com
Thu Jul 15 19:57:34 EDT 2004


Daniel Convissor wrote:

> "If a second call is made to mysql_connect() with the same arguments, no
>
>new link will be established, but instead, the link identifier of the 
>already opened link will be returned."
>  -- http://us3.php.net/mysql_connect
>  
>

I didn't believe this when I first read it, but can confirm:

$dbcon1 = mysql_connect( $h, $u, $p );
mysql_select_db( 'clew', $dbcon1 );

$dbcon2 = mysql_connect( $h, $u, $p );
mysql_select_db( 'chxo', $dbcon2 );

$result = mysql_query( "show tables",  $dbcon1 );
while ( $record = mysql_fetch_array( $result ) ) {
  print $record[0]."<br />";
}

... will show the tables in the "second" database, even though the query 
was sent via the "first" connection.

Weird.



More information about the talk mailing list