简体   繁体   中英

Can't connect to mysql server

I'm creating a php page (on a godaddy server) which needs to connect to a mysql server and retrieve data from a database. When i run the page i got an error message stating that.

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on **

It says that the error is on the below line,

$conn=mysql_connect($dbhost,$username,$password);

My doubt is,

What needs to be given in place of username and password? Right now i've given the username and password used while creating a new database inside mysql. What am i doing wrong?

Thanks in advance...

On shared go daddy DB's you can't use localhost for the $dbhost

you will need to use the location specified in your godaddy mysql cp

Do not use "localhost" as the hostname for your database-driven websites. Once you have successfully created a database, your host name displays on the Database Information page of your hosting Control Panel.

To Find the Host Name for Your Database

  1. Log in to your Account Manager.
  2. Click Web Hosting.
  3. Next to the hosting account you want to use, click Launch.
  4. In the Databases section of the hosting Control Panel, click MySQL or MSSQL depending on the database type for which you want the host name.
  5. From your list of databases, click Actions next to the database you want to use, and then click Details.

Your database host name displays in the Hostname field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM