|
Posted by Kurda Yon on 04/26/07 18:50
Hi everybody,
I cannot understand the following thinks. The last line of the
fillowing code produces a message about mistake (not a valid MySQL-
Link resource):
$link = mysql_connect( "localhost","tmp_user","tmpxxx" );
mysql_select_db( $db_name, $link);
$link = mysql_connect( "localhost","tmp_user","tmpxxx" );
mysql_close( $link );
mysql_select_db( "sss", $link );
It is clear why it is happens. Because I use $link to the database,
which has been closed in the previouse line. To remove this problem I
have to change the code in the following way:
$link = mysql_connect( "localhost","tmp_user","tmpxxx" );
mysql_select_db( $db_name, $link);
$link_new = mysql_connect( "localhost","tmp_user","tmpxxx" );
mysql_close( $link_new );
mysql_select_db( "sss", $link );
Now I do the same but with the usage of a function. As it is expected,
the following code produce the message about mistake:
$link = mysql_connect( "localhost","tmp_user","tmpxxx" );
mysql_select_db( $db_name, $link);
function fff()
{
$link = mysql_connect( "localhost","tmp_user","tmpxxx" );
mysql_close( $link );
}
fff();
mysql_select_db( "sss", $link );
But what is strange and what I cannot understand is why the previosly
used solution does not work. The following code alse generate the same
message!
$link = mysql_connect( "localhost","tmp_user","tmpxxx" );
mysql_select_db( $db_name, $link);
function fff()
{
$link_new = mysql_connect( "localhost","tmp_user","tmpxxx" );
mysql_close( $link_new );
}
fff();
mysql_select_db( "sss", $link );
Thanks.
Navigation:
[Reply to this message]
|