|
Posted by Kurda Yon on 04/27/07 14:56
On Apr 27, 3:02 pm, Schraalhans Keukenmeester <inva...@invalid.spam>
wrote:
> On Fri, 27 Apr 2007 04:53:04 -0700, Kurda Yon wrote:
> > It is me again. It seems that I solve the previous problem (with your
> > help) but get a new one (which seems to be very related to the
> > previous one).
>
> > This part of code produce a message about mistake:
>
> > $link = mysql_connect( "localhost","tmp_user","pswxxx" );
> > function fff()
> > {
> > $link_new = mysql_connect( "localhost","tmp_user","pswxxx", true );
> > mysql_close( $link_new );
> > }
> > fff();
> > mysql_select_db( "sss", $link );
> > $result = mysql_query( "select * from root" );
>
> > The message is:
> > Access denied for user: 'nobody@localhost' (Using password: NO)
> > A link to the server could not be established
>
> > It complains about the last line. And this message disappears if I do
> > not coll the function fff (I replace fff(); by //fff();).
>
> > Can anybody explain this behavior? It seems that connection made to
> > the database in the function somehow influences on other connection.
>
> I'm guessing here: You use literal strings here in your post making the
> mysql connection, but do you perhaps use variables in your real code? If
> so, (and assuming globals are off) the function doesn't see these
> variables unless you specify them global in the function.
>
> Other than that, I can't think of anything right now. I cannot reproduce
> the error anyway with my code (below).
>
> <?PHP
> require 'dbdata.inc.php';
> $link = mysql_connect($dbhost,$dbuser,$dbpasswd);
> function dbopen() {
> global $dbhost, $dbuser, $dbpasswd;
> $new_link = mysql_connect($dbhost,$dbuser,$dbpasswd,true);
> mysql_close($new_link);}
>
> dbopen();
> mysql_select_db($dbname,$link);
> $result= mysql_query('select count(*) from customers',$link);
> $row = mysql_fetch_row($result);
> echo $row['0']; // outputs 13, oughtta be closer to 50 if you ask me;-)
> ?>
Thank you for your code. I have compared it with my code (line by
line) and found out that the origin of the mistake was that I did not
put $link, as the second argument of the function mysql_query (in the
last line).
Thanks!
[Back to original message]
|