Jump to content
Larry Ullman's Book Forums
Sign in to follow this  

Recommended Posts

I am wondering if someone can help me with an intermittent database connection problem that I have started to experience.

 

My  environment is:
. Windows 7 Home Premium 64 bit
. Internet Explorer 10
. Firefox 22.0
. Dreamweaver MX2004 as the text editor
. Xampplite 1.7.3 which comprises:
.. Apache 2.2.14
.. PHP 5.3.1
.. MySQL 5.1.41


The problem occurs intermittently in both IE10 and Firefox, so appears not to be related to the browser.

 

The message that I get is (and I stress that I don't always get it):

 

Warning - mysql_connect()  [function MySQL-connect]: Unknown MySQL server host 'localhost' (11001) with a reference to the PHP line of code. This is immediately followed by Fatal error Unknown MySQL server host 'localhost' (11001) with a reference to the same PHP line of code.

 

My connection code is:

 

$dbc = mysql_connect($local_hostname_xx, $local_username_xx, $local_password_xx) or trigger_error(mysql_error(),E_USER_ERROR);

 

I am using the PHP mysql functionality as the production system does not support the mysqli functionality.

 

If I have a look at the database with HeidiSQL (which provides MySQL admin-like functionality) the database and its data are all there. 

 

Can you also provide some specific guidance re the following:

1) I have a lot of PHP scripts that enable an administrator to update many aspects of the database tables.  Most use Larry's PHP redux technique.  In each script I require_once the php connection code followed immediately by the mysql_select_db statement. Should I be using 'require' rather than 'require_once'?

2) The database connection code does not use a persistent mysql_connect - should I be using a persistent connection i.e., mysql_pconnect function instead?

3) I do not close the database connection in the PHP scripts - should I?

 

I have been using similar code for years without a problem. The problem seems to have started when I was experimenting with 'require' and 'require_once' to include the database connection code. I was also experimenting with mysql_connect versus mysql_pconnect in the connection code itself.

 

Any advice will be most appreciated and thank you in anticipation.

 

Best regards, Necuima.

 

 

 

 

Share this post


Link to post
Share on other sites

Hi HartleySan,

 

Thanks for getting back to me, but as I mentioned in my post, I can't use the mysqli functions because the production hosting company does not support them.

 

I would certainly use them if I could!

 

Cheers from Oz.

Share this post


Link to post
Share on other sites

I did more Google searching and came across this advice:

 

"An 11001 error means that the name you provided for a server in the client connection cannot be resolved to an IP address because DNS entries for that host name cannot be found. Try using the appropriate (internal or external) IP address for the server in the client connection string instead of the name".

 

So I am trying my internal IP address plus the :3306 port number suffix instead of 'localhost' (in the mysql_connect) - so far so good but I'll post more info after more tests.

 

But if anyone can give me some guidance on my 3 questions above, I'll be very happy to receive it.

 

Thanks, Necuima.
 

Share this post


Link to post
Share on other sites

1) I have a lot of PHP scripts that enable an administrator to update many aspects of the database tables.  Most use Larry's PHP redux technique.  In each script I require_once the php connection code followed immediately by the mysql_select_db statement. Should I be using 'require' rather than 'require_once'?

 

No, it's fine as is.

 

2) The database connection code does not use a persistent mysql_connect - should I be using a persistent connection i.e., mysql_pconnect function instead?

 

No, you should not be using persistent connections.

 

3) I do not close the database connection in the PHP scripts - should I?

 

If you want to be precise, you can, but it really shouldn't matter.

 

Share this post


Link to post
Share on other sites

Hi Larry,

 

Thanks for the advice - I will add the mysql_close as I'd like to have all the scripts totally correct.

 

Re the connection problem, since I changed the host name to the IP address form, it has worked perfectly.  But I still don't understand why the previous form, which was just 'localhost' failed intermittently. Do you have any insights?

 

And thanks again,

 

Cheers from Oz.

Share this post


Link to post
Share on other sites

I have never seen that before and would have assumed that the problem was using an installation on your own computer. It's crazy to me that it would happen on a hosted site.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...