CXCODER CXCODER - 4 years ago 166
SQL Question

MySQL PDO won't connect

I'm trying to connect with my database but it wont connect.
It seems like it gives me a error, that it can not find the database

session_start();

$DB_host = "localhost";
$DB_user = "admin";
$DB_pass = "8UHbJLimfU";
$DB_name = "admin";

try
{
$DB_con = new PDO("mysql:host={$DBhost};dbname={$DBname}",$DB_user,$DB_pass);
$DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo $e->getMessage();
}


include_once 'class.user.php';
$user = new USER($DB_con);


Does someone know where the problem is?

Answer Source

Change this:

mysql:host={$DBhost};dbname={$DBname}

To this:

mysql:host={$DB_host};dbname={$DB_name}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download