I have a project and I have deployed it in my server with IP 192.168.1.5
When I access my project using 192.168.1.5/project
It runs OK When I tried to run my project in my localhost like 127.0.0.1/project
My PDO connection is null And I dont understand why. MY connection is:
define('DBHOST', '192.168.1.5');// database host address - localhost is usually fine
define('DBNAME', 'dbname');// database name - must already exist
define('DBUSER', 'username');// database username - must already exist
define('DBPASS', 'password');
try {
$dbh = new PDO("mysql:host=".DBHOST."", "".DBUSER."", "".DBPASS."", array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES latin1 COLLATE latin1_general_ci"));
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbname = "`" . str_replace("`", "``", DBNAME) . "`";
$dbh->query("CREATE DATABASE IF NOT EXISTS $dbname");
$dbh->query("SET NAMES 'utf8'");
$dbh->query("use $dbname");
} catch (PDOException $e) {
echo "\nPDO::errorInfo():\n";
print_r($dbh->errorInfo());
echo "\n\n";
echo 'Connection failed: ' . $e->getMessage();
}
My connection goes to catch part and returns this error:
PDO::errorInfo():
Fatal error: Call to a member function errorInfo() on a non-object in
When I try to var_dump($dbh)
I get NULL
Why is not working when I run localhost and when I run in remote server it does run..
Reason Why I want to run in localhost:
Is so that I can do it faster. Right now I need to upload the changes in server to see the result. I want to run in localhost so I dont need to upload to see changes