Re: Unable to connect to the database
Posted by:
Jones NDI
Date: June 09, 2016 01:59PM
I have tested the following code to connect to the DB as the only code in my index.php:
<?php
DEFINE ('DB_HOST', 'database_host'); // The database host ie: loacalhost etc;
DEFINE ('DB_USER', 'user_name'); // The database users name- root
DEFINE ('DB_PASSWORD', 'user_password'); // The database password - xxxxxx
DEFINE ('DB_NAME', 'database_name'); // The database name - my_database
// Connect to the MySQLi Database
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Check for a MySQLi Connection
if (mysqli_connect_errno())
{
echo "Failed to Connect to MySQL: " . mysqli_connect_error();
}
else
{
echo "Connection to MySQLi Ok! " . mysqli_connect_error();
}
mysqli_close($conn);
?>
And it could not connect still. The error msg is:
"Failed to Connect to MySQL: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)"
Thanks in advance for further suggestion.
Subject
Written By
Posted
Re: Unable to connect to the database
June 09, 2016 01:59PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.