Help !! This host is unknown when you connect to the local database.

Source: Internet
Author: User
Help !! When I connect to the local database, I do not know that such a host is installed with wamp. php, the results show that you do not know such a host, first aid ........


Reply to discussion (solution)

Do not explain the error message by yourself, because you do not know its meaning.
Otherwise, you do not need to ask questions.

Please provide the original English error message!

(! ) Warning: mysql_connect () [function. mysql-connect]: php_network_getaddresses: getaddrinfo failed: Unknown host. In C: \ wamp \ www \ testmysql. php on line 2
Call Stack
# Time Memory Function Location
1 0.0008 670776 {main} () .. \ testmysql. php: 0
2 0.0008 671064 mysql_connect () .. \ testmysql. php: 2

(! ) Warning: mysql_connect () [function. mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: Unknown host. (Trying to connect via tcp: // hostname: 3306) in C: \ wamp \ www \ testmysql. php on line 2
Call Stack
# Time Memory Function Location
1 0.0008 670776 {main} () .. \ testmysql. php: 0
2 0.0008 671064 mysql_connect () .. \ testmysql. php: 2

(! ) Warning: mysql_connect () [function. mysql-connect]: php_network_getaddresses: getaddrinfo failed: Unknown host. In C: \ wamp \ www \ testmysql. php on line 2
Call Stack
# Time Memory Function Location
1 0.0008 670776 {main} () .. \ testmysql. php: 0
2 0.0008 671064 mysql_connect () .. \ testmysql. php: 2
Cocould not connect to MySQL: php_network_getaddresses: getaddrinfo failed: Unknown host.

This is the error message ......

Post the first three lines of C: \ wamp \ www \ testmysql. php

$ Link = mysql_connect ('hostname', 'dbuser', 'dbpassword ');
If (! $ Link ){
Die ('could not connect to MySQL: '. mysql_error ());
}
Echo 'connection OK '; mysql_close ($ link );
?>
This is all the code for testmysql. php.

How can I use hostname like this?
It should be defined as a variable and added in the second line:
$ Hostname = 'localhot ';
$ Dbuser = 'root ';
$ Dbpassword = ''; // enter your database password.

$ Link = mysql_connect ('hostname', 'dbuser', 'dbpassword'); changed
$ Link = mysql_connect ($ hostname, $ dbuser, $ dbpassword );

$ Link = mysql_connect ('localhost', 'dbuser', 'dbpassword ');

I tried it, but there are still such errors.

This error has changed


(! ) Warning: mysql_connect () [function. mysql-connect]: Access denied for user 'dbuser' @ 'localhost' (using password: YES) in C: \ wamp \ www \ testmysql. php on line 2
Call Stack
# Time Memory Function Location
1 0.0007 671144 {main} () .. \ testmysql. php: 0
2 0.0007 671432 mysql_connect () .. \ testmysql. php: 2
Cocould not connect to MySQL: Access denied for user 'dbuser' @ 'localhost' (using password: YES)

What are the usernames and passwords of your database? if you use a variable, you have assigned a value to the variable.

Check your database configurations.

Thanks. you can connect to the database. the default password is null.

In fact, you only need
$ Link = mysql_connect ();
You can.

In the tutorial
$ Link = mysql_connect ('hostname', 'dbuser', 'dbpassword ');
Is used:
Enter the database host name in the hostname field
Enter the database username in dbuser
Enter the password in dbpassword

Default parameter
Mysql_connect ()
Equivalent
Mysql_connect ('localhost', 'root ','')


In fact, you only need
$ Link = mysql_connect ();
You can.

In the tutorial
$ Link = mysql_connect ('hostname', 'dbuser', 'dbpassword ');
Is used:
Enter the database host name in the hostname field
Enter the database username in dbuser
Enter the password in dbpassword

Default parameter
Mysql_connect ()
Equivalent
......

As he said, I tried it. what is the result?

At the beginning, wamp also found this problem. solution:
My database user is the root password 123456
Set to $ link = mysql_connect ('localhost', 'root', '123 ');
The connection is successful.

Yes. the test is successful in this way.

But what is the database password when someone else invades this file?

At the beginning, wamp also found this problem. solution:
My database user is the root password 123456
Set to $ link = mysql_connect ('localhost', 'root', '123 ');
The connection is successful.
I want to ask how to change it. no, an error occurs when you change the brackets directly. sorry! Urgent...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.