Jump to content

Database connection failed: ... No such host is known.


kimsbutt
Go to solution Solved by requinix,

Recommended Posts

( ! ) 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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Solution

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.
Link to comment
Share on other sites

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.