HI there,
I am having a strange issue. I have a php script that says it is connected but when I check the connection object (a few lines of code later), I get error message:
// Include connect.php which has connect function
require('connect.php');
// Get connection Object from connect function
$conn = connect(); // Prints: Connection is Successful
// Check connection
if( $conn === false){
die("ERROR: Could not connect. " . mysqli_connect_error()); // Prints: Could not connect. Access denied for user ''@'localhost' (using password: NO)
}
My code for connect is as follows
<?php
function connect()
{
// Path to Config File
$config = parse_ini_file('/var/www/vhosts/*******/db.ini');
$conn = mysqli_connect("localhost",$config['username'],$config['password'],$config['db']);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
else
{
echo "Connection is successful";
}
return $conn;
}
?>
Its as if the $conn object is NOT being returned properly in the connect() function. This code has worked in other sites.
Any ideas?