Jump to content

Recommended Posts

Hi. I am having trouble with the mysql_connect function. When I try it I get the "Can't get hostname for your address" error. I have enabled skip-name-resolve on my mySQL server, and I am positive this error has something to do with PHP, not the mySQL server because this works from the EasyPHP, but not my actual web server. Here are the details:

 

MySQL server:

OS: Windows 7

IP: 192.168.0.188

Port: 3306

Version: 5.5.8

 

skip-name-resolve is in the my.ini configuration file under [mysqld], as it should be.

remote connections are enabled, and work from other machines.

 

PHP connecting client:

OS: Ubuntu Server 10.04.3

IP: 192.168.0.198

Apache Version: 2.2.14

PHP version: 5.3.2-1ubuntu4.10 with Suhosin-Patch (cli)

 

Code:

<?php
$con = mysql_connect("192.168.0.188:3306","root","password");
if (!$con)
   {
   die('Cant Connect: ' . mysql_error());
   }
?>

 

That code is saved in a .php file as test.php. When I visit it from my PC's version of EasyPHP (5.3.8.0) everything works fine, but when I visit the same page when its hosted on my Ubuntu server, I get "Could not connect!: Can't get hostname for your address". I just need my Ubuntu server to be able to connect to the mySQL server with PHP. Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/251125-cant-get-hostname-for-your-address/
Share on other sites

 

try using localhost instead

$con = mysql_connect('localhost','root','password');

 

or even

$con = mysql_connect('example.com:3306','root','password');

 

or

$con = mysql_connect('127.0.0.1:3306','root','password');

Hi! Thanks for your reply. It works fine from the Ubuntu server when I connect to localhost using '127.0.0.1' OR 'localhost' with or without the port. Still won't work when I try to connect to the remote MySQL server though. Any Ideas?

 

P.S. How do I disable the verification question? Incredibly annoying.

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.