ddd1600 Posted March 12, 2012 Share Posted March 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/ Share on other sites More sharing options...
xyph Posted March 12, 2012 Share Posted March 12, 2012 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] Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/#findComment-1326268 Share on other sites More sharing options...
Pikachu2000 Posted March 12, 2012 Share Posted March 12, 2012 Where did you get that IP address from? Is MySQL on your local machine, or is it on a hosted server? Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/#findComment-1326269 Share on other sites More sharing options...
ddd1600 Posted March 12, 2012 Author Share Posted March 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/#findComment-1326272 Share on other sites More sharing options...
xyph Posted March 12, 2012 Share Posted March 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/#findComment-1326273 Share on other sites More sharing options...
ddd1600 Posted March 12, 2012 Author Share Posted March 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/#findComment-1326274 Share on other sites More sharing options...
ddd1600 Posted March 12, 2012 Author Share Posted March 12, 2012 I've pinged 192.168.0.8 and all packets went through. Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/#findComment-1326275 Share on other sites More sharing options...
xyph Posted March 12, 2012 Share Posted March 12, 2012 Hehehe You leave that part out, the query is: SELECT `user`,`password` FROM `mysql`.`user`; Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/#findComment-1326276 Share on other sites More sharing options...
ddd1600 Posted March 12, 2012 Author Share Posted March 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/#findComment-1326278 Share on other sites More sharing options...
Pikachu2000 Posted March 12, 2012 Share Posted March 12, 2012 You're using single 'quotes' where you should be using `backticks`. Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/#findComment-1326279 Share on other sites More sharing options...
ddd1600 Posted March 12, 2012 Author Share Posted March 12, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/258704-mysql_connection-problems-getaddrinfo-failed-no-such-host-is-known/#findComment-1326280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.