Jump to content

mysql_connect behaviour


hoppyite

Recommended Posts

Hi all,

 

I have a function to connect to mysql which can be called several times during the running of a script:

 

	function ConnectToDb($server, $user, $pass, $database)
{
	$s = mysql_connect($server, $user, $pass); //or die ( "<H3>Server unreachable</H3>");
	$d = mysql_select_db($database, $s);

	if(!$s || !$d)
		return false;
	else
		return true;
}

 

The function and script works fine. But if I remove the comments so that the mysql_connect reads:

 

$s = mysql_connect($server, $user, $pass) or die ( "<H3>Server unreachable</H3>");

 

Then the first attempt to connect works fine but a second attempt  to connect fails and the script dies here.

 

Does anyone know why this happens?

 

Thanks in advance.

 

John

Link to comment
Share on other sites

Hi Thorpe,

 

Thank you for replying.

 

I tried to find out the error as suggested but nothing is returned from mysql_error().

 

John

 

PS: sorry mean't  to add that as soon as the 'or die' is included the script does just that. So I don't think it even gets as far as evaluating my_sql_error()!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.