1

I have bought a Web Hosting on Godaddy. I worked on my website with WampServer and the following code worked good. Now, with Godaddy it doesn't work.

@mysql_connect('localhost', 'root', '');
@mysql_select_db('neiasite');

Can you help me please?

Thanks for reading.

Mori
  • 9
  • 1
  • 4

3 Answers3

1

In Godaddy, or any other shared hosting, you will not be given root user access to database. You need to create an user and password for your database.

This link will explain how.

https://support.godaddy.com/help/article/36/creating-mysql-or-sql-server-databases-for-your-hosting-account

And you need to use MySQLi to connect

$link = mysqli_connect("localhost","use_your_username","use_your_password","your_database_name") or die("Error " . mysqli_error($link)); 
Gopakumar Gopalan
  • 1,187
  • 14
  • 22
  • Thank you everyone for helping me. @Gopakumar Gopalan - I have made a new user now and used the following: @mysql_connect('localhost', 'used_my_username_here', 'used_my_password_here''); @mysql_select_db('neiasite'); Still does not work. – Mori Feb 24 '15 at 13:03
  • It says "error" when I reload the page, but I have no clue what the problem is. @Gopakumar Gopalan – Mori Feb 24 '15 at 13:40
  • I think that I tried almost everything and still failed. Does anyone have another suggest? – Mori Feb 24 '15 at 13:56
  • By the way, the PHP's file name is "config.php", do I have to change it to "wp-config.php", Or it doesn't matter? – Mori Feb 24 '15 at 14:07
0

Remember to import you existing database to godaddy from your localhost.

And i guess you should take a look at this tutourial on how to connect to godaddy mysql

http://www.prophoto.com/support/godaddy-mysql/

Jesper
  • 3,816
  • 2
  • 16
  • 24
-1

Hola! Thank you so very much for helping me.

I have successfully fixed it with this code:

mysql_connect("localhost", "username", "password")or die("cannot connect to server");
mysql_select_db("db_name")or die("cannot select db");

Source: http://www.phpeasystep.com/mysql/4.html.

Pce. (:

@Arun, @Andre, @Gopakumar Gopalan, @Djip

Mori
  • 9
  • 1
  • 4
  • I'm glad to see that you solved it. But you should move to `mysqli` as it is deprecated and will be removed, and that time your program will throw an error. For more info read this -> http://stackoverflow.com/questions/13944956/the-mysql-extension-is-deprecated-and-will-be-removed-in-the-future-use-mysqli – Gopakumar Gopalan Feb 24 '15 at 16:20
  • I moved to "mysqli", it says "cannot connect to server". @Gopakumar Gopalan – Mori Feb 24 '15 at 18:51
  • May be your server dont have mysqli module. see `phpinfo()`. – Gopakumar Gopalan Feb 24 '15 at 20:23