-4

I have spent my few hours on finding out why mysql_connect('localhost', 'root', ''); works fine on localhost but

mysql_connect('mysite.com', 'root', ''');

does not works on the server ,

can anyone please help !!!

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
Abhay Kumar
  • 5,048
  • 2
  • 16
  • 21

3 Answers3

0

Some checklist in my mind right now:

1.use

ini_set('display_errors',1); 

or check the php error log to see if there is anything wrong.

2.try to connect to your MySQL server using a console such as sqlyog or any other consoles with user/password you use in your php code.

3.check if the srever that runs php codes have access to MySQL server.

Toraj
  • 1
  • 3
0

Don't use mysql methods it is deprecated.
You can use PDO or mysqli
PDO as:

try{
   $username = 'root';
   $dbname = 'mysql:host=mysite.com';
   $password = 'password';
   $conn = new PDO($dbname, $username, $password);
   $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   // do things here
}
catch(Exception $e){
   //error
   echo $e->getMessage();
}
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Ikari
  • 3,176
  • 3
  • 29
  • 34
-1

Warning

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

So use
- mysqli_connect()
- PDO::__construct()

sanoj lawrence
  • 951
  • 5
  • 29
  • 69