I'm trying to connect to my SQL database and I'm getting the error mentioned above.
This is the PHP code
// This file has database info variables (password etc.)
include "db_config.php";
class DB_CONNECT
{
function __construct()
{
$this->connect();
}
function __destruct(){}
function connect()
{
$connect = mysql_connect($db_server, $db_user, $db_password) or die();
$db = mysql_select_db($db_name) or die();
echo "Connection successful!";
return $connect;
}
}
// Just to try out if the connection is successful
new DB_CONNECT();
This is the error
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /hermes/bosnaweb05a/b1/ipg.matejhacincom1/dbtest/db_connect.php on line 16
The funny thing is that I can connect to the database easily with this code which is generated for db testing by my hosting provider:
$link = mysql_connect('my db server', 'db user', 'db pass');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db(my db table);
Could someone let me know what I'm doing wrong? I have no idea anymore.
The reason I mentioned that I'm not the server adming is because I saw a lot of questions like this here, but all of them have instructions how to solve it by using some server commands etc.