Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

PHP Remote Server Database Connection Error

php database mysqli connection error

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1 KodeKool

KodeKool

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 276 posts

Posted 01 March 2013 - 10:32 AM

Hey guys,

               So here's my issue, im doing some work for a client. and am finalizing the site by including the database information; however, i can't seem to connect to the database, which brings me to my question.

 

Using mysqli in php. how come the only thing you can connect to is localhost? everytime i've tried an actual URL it won't connect to the database. I always end up getting this error.

 

Warning: mysqli_real_connect(): [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connecti (trying to connect via tcp://serverName:port)

 

i know why im getting the error. but it seems no matter which way i try to connect, it doesn't work. has anybody run into this problem as well? and if so, did you find a way around it?

 

I know you can work around it by placing this code on the local machine where the database is and changing the connection to localhost. but im not at that point yet and need to be able to connect outside of the local machine. any ideas?


~A program will always do what you tell it to do, and seldom what you want it to do~

Check out my latest PHP tutorial


#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 01 March 2013 - 11:38 AM

Well, aside the obvious needs ( a working server in the outside ), you need to address to things, 1 maybe you should increase the timeout for the connection, and then make sure the port is not blocked by any of the firewalls in the tcp route.

Usually, firewalls, proxies, etc has ports closed by default, you need to open then so the communication can flow.



#3 KodeKool

KodeKool

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 276 posts

Posted 01 March 2013 - 11:43 AM

lol. the servers up and working and all :P , but wouldn't i just be able to use the open port to connect? and what advantage would increasing the timeout do? if the connections proper, why wouldn't the default timeout work?


~A program will always do what you tell it to do, and seldom what you want it to do~

Check out my latest PHP tutorial


#4 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts

Posted 01 March 2013 - 02:06 PM

A firewall can be blocking your application to connect to a remote server. The web server could be bound to only use the loopback ip.


I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#5 KodeKool

KodeKool

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 276 posts

Posted 01 March 2013 - 07:47 PM

so in plain text english, there's no real way to connect my code to the server unless it's on the host system? or i change the firewall settings?


~A program will always do what you tell it to do, and seldom what you want it to do~

Check out my latest PHP tutorial


#6 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts

Posted 02 March 2013 - 10:59 AM

well, probably. but we can't be sure unless we have investigated further, for example, do the remote server accept connections from your server? many database servers is configured to only accept localhost connections for security reasons.


I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#7 KodeKool

KodeKool

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 276 posts

Posted 02 March 2013 - 11:19 AM

probably not. seeing as how i can't access it through this machine, lol. alright. i'll have to make other arrangements then :P which makes it a bit more difficult, but i think i can manage, thanks for your help guys, much appreciated :P


~A program will always do what you tell it to do, and seldom what you want it to do~

Check out my latest PHP tutorial





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download