EDIT: SOLVED
I'm trying to pass some variables for a mysql connection from a separate file. However, they seem to only be coming through in a string and not as variables.
connect.php:
<?php
function connect(){
require ($_SERVER['DOCUMENT_ROOT'].'/db-connect.php');
$conn1 = new mysqli($servername, $username, $password, $dbname);
if ($conn1->connect_error) {
die("Connection failed: " . $conn1->connect_error);
}
echo $conn1->host_info . "
";
}
connect();
?>
db-connect.php:
<?php
$servername = "localhost";
$username = "-";
$password = "--";
$dbname = "---";
?>
Message coming through:
$servername = "localhost"; $username = "-"; $password = "--"; $dbname = "---";Connection failed: Access denied for user '-'@'localhost' (using password: NO)
notes: The $password at the end is different that what is in the db-connect.php file. It is an older password that I used to have when I first tried it. Also, the user '-'@'localhost' is an old user and not the user from $username.
Any ideas please and thanks? Matt
Perhaps this way around may work better for you.
<?php
require ($_SERVER['DOCUMENT_ROOT'].'/db-connect.php');
function connect(){
global $servername, $username, $password, $dbname;
$conn1 = new mysqli($servername, $username, $password, $dbname);
if ($conn1->connect_error) {
die("Connection failed: " . $conn1->connect_error);
}
echo $conn1->host_info . "
";
}
connect();
?>