kimsbutt Posted May 10, 2013 Share Posted May 10, 2013 ( ! ) SCREAM: Error suppression ignored for ( ! ) Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\widget_corp\includes\connection.php on line 4 Database connection failed: php_network_getaddresses: getaddrinfo failed: No such host is known. I am getting the error. I'm doing the PHP essential training course on Lynda.com. The teacher asked to make a constant.php file and then use constants to store the db user pass etc and then call it via the constant name or whatever and now i'm getting that huge error. I've been stuck for 2 days. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/277900-database-connection-failed-no-such-host-is-known/ Share on other sites More sharing options...
requinix Posted May 10, 2013 Share Posted May 10, 2013 No such hostshould be a hint. You sure you have the right hostname? Quote Link to comment https://forums.phpfreaks.com/topic/277900-database-connection-failed-no-such-host-is-known/#findComment-1429606 Share on other sites More sharing options...
kimsbutt Posted May 10, 2013 Author Share Posted May 10, 2013 should be a hint. You sure you have the right hostname? Thanks for replying. Yes, i was just trying random things, turns out it works if i use the actual host name, server, pass, and databasename but the instructor tells you to make a seprate php file which contains the info as such: <?php //Database Constants define("SERVER", "localhost"); define("USER", "root"); define("PASS", "asdsfsadfsdfsd"); define("NAME", "widget_corp"); ?> and then on the content file link to it like so: <?php $connection = mysql_connect("SERVER","USER","PASS"); if(!$connection){ die("Database connection failed: " . mysql_error()); } //2.Select a database to use $db_select = mysql_select_db("NAME", $connection); if(!$db_select){ die("Database selection failed: " . mysql_error()); } ?> So I guess now my question is why doesn't constants work for me? Quote Link to comment https://forums.phpfreaks.com/topic/277900-database-connection-failed-no-such-host-is-known/#findComment-1429610 Share on other sites More sharing options...
Solution requinix Posted May 10, 2013 Solution Share Posted May 10, 2013 You only need the quotes when you define the constant. define("SERVER", "localhost");Afterward, no quotes. $connection = mysql_connect(SERVER, USER, PASS);Otherwise PHP thinks you have a regular string and will happily use those as the values. Quote Link to comment https://forums.phpfreaks.com/topic/277900-database-connection-failed-no-such-host-is-known/#findComment-1429612 Share on other sites More sharing options...
Barand Posted May 10, 2013 Share Posted May 10, 2013 Did you include() the file with the constants in your second file? Quote Link to comment https://forums.phpfreaks.com/topic/277900-database-connection-failed-no-such-host-is-known/#findComment-1429616 Share on other sites More sharing options...
kimsbutt Posted May 11, 2013 Author Share Posted May 11, 2013 Holy shnitzel! it worked! Thank you requinix!!! Quote Link to comment https://forums.phpfreaks.com/topic/277900-database-connection-failed-no-such-host-is-known/#findComment-1429621 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.