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