|
Posted by Kurda Yon on 04/27/07 08:47
On Apr 26, 9:20 pm, "Steve" <no....@example.com> wrote:
> "Kurda Yon" <kurda...@yahoo.com> wrote in message
>
> news:1177613411.140647.31800@n35g2000prd.googlegroups.com...
> | 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 );
>
> hard to understand you.
>
> is this your *real* code? you realize that $link INSIDE the function is not
> $link OUTSIDE your function, right? why are you worrying about closing the
> connection anyway? the connection is dropped after the script is run/exited.
Sorry, may be I explained it in a bad way. The problem is that the
following code produce a message about mistake:
$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 );
Or more precisely the last line causes the following message:
Warning: mysql_select_db(): 2 is not a valid MySQL-Link resource
And it happens only if I execute the fff() function before. I suppose
that origin of the problem is that I close connection to the database
in the function. But I do not understand why. I do give another name
to the connection.
Navigation:
[Reply to this message]
|