Jump to content

Archived

This topic is now archived and is closed to further replies.

ddd1600

mysql_connection problems -- 'getaddrinfo failed', "No such host is known"

Recommended Posts

I'm just doing a tutorial, learning PHP/mySQL for the first time, and have been having problems getting PHP to talk to mySQL, so to speak.

 

The tutorial is from here:

 

Here is the code:

 

        <?php

       

$link = mysql_connect('http://192.168.0.8:3307', 'ddd1600', '');

if (!$link) {

    die('Could not connect: ' . mysql_error());

}

 

// make foo the current db

$db_selected = mysql_select_db('test', $link);

if (!$db_selected) {

    die ('Could not connect: ' . mysql_error());

}else{

    echo "It worked!";

}

 

        $sql =

"INSERT INTO `test`.`Table2` (

`ID` ,

`name` ,

`content`

)

VALUES (

NULL ,  'apples',  'are grown by Australians.');"

       

      ; ?>

 

 

My server is on my private network, by the way.

 

Thanks!

 

PS:

If it helps, here is the error message from Chrome browser or any other browser:

Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\PhpProject1\index.php on line 4

 

Warning: mysql_connect() [function.mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (trying to connect via tcp://http:3306) in C:\xampp\htdocs\PhpProject1\index.php on line 4

 

Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\PhpProject1\index.php on line 4

Could not connect: php_network_getaddresses: getaddrinfo failed: No such host is known.

Share this post


Link to post
Share on other sites

Can you ping the server? Are you sure a firewall or something isn't blocking communication?

 

Is the server running on the local computer? If so, use 'localhost' instead

 

[edit] Oh derp! Take the http:// out of the hostname :/ You aren't connecting to a web server! [/edit]

Share this post


Link to post
Share on other sites

Where did you get that IP address from? Is MySQL on your local machine, or is it on a hosted server?

Share this post


Link to post
Share on other sites

mysql is being hosted on a computer in my local wifi network (in my apartment). The server is sitting right next to me on a different PC. That IP is the private IP for the server in the network.

 

UPDATE:

- Great, so I dropped the http://, and now have a new error message. Thanks for the quick response guys

- I'm not sure if this helped or not, but I added a separate user on phpMyadmin with the host "127.0.0.1" in addition to the "localhost" one.

 

Here's the new error message:

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ddd1600'@'SERVER' (using password: YES) in C:\xampp\htdocs\PhpProject1\test.php on line 4

Could not connect: Access denied for user 'ddd1600'@'SERVER' (using password: YES)

 

NOTE!!! : I added a password

 

Share this post


Link to post
Share on other sites

Go into your MySQL console as root, and run a query like

 

mysql> SELECT `user`,`password` FROM `mysql`.`user`;
+------+----------+
| user | password |
+------+----------+
| root |          |
| root |          |
| root |          |
|      |          |
+------+----------+
4 rows in set (0.03 sec)

 

If the user exists, verify it's permissions.

Share this post


Link to post
Share on other sites

Go into your MySQL console as root, and run a query like

 

mysql> SELECT `user`,`password` FROM `mysql`.`user`;
+------+----------+
| user | password |
+------+----------+
| root |          |
| root |          |
| root |          |
|      |          |
+------+----------+
4 rows in set (0.03 sec)

 

If the user exists, verify it's permissions.

 

I tried running that several times through the SQL cmd prompt on phpMyAdmin, but got a syntax error message every time. It especially doesn't like that 'mysql' bit.

 

Anyway, I'm not sure if this is the same thing, but under Privileges in phpMyAdmin I've verified the existence of user "ddd1600", which has all permissions.

Share this post


Link to post
Share on other sites

Hehehe

 

You leave that part out, the query is:

SELECT `user`,`password` FROM `mysql`.`user`;

Share this post


Link to post
Share on other sites

Oh I know that, I didn't include the mysql>.

 

Anyway, here's the error message:

 

"#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''mysql'.'user'' LIMIT 0, 30' at line 1

Share this post


Link to post
Share on other sites

You're using single 'quotes' where you should be using `backticks`.

Share this post


Link to post
Share on other sites

WOW. That is ridiculous.

 

So first I changed all '..'s to `...`.

 

But then it said "no host selected" (but no error message).

 

So then I changed `test` to "test" and BAM! "It worked!"

 

I was really started to get depressed thanks guys problem resolved!

Share this post


Link to post
Share on other sites

×
×
  • 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.