Reputation: 441
I have db.php with the following code.
<?php
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "password";
$dbName = "test";
$databaseLink = new mysqli ($dbHost, $dbUser, $dbPass);
if($databaseLink)
{
mysqli_select_db($databaseLink,$dbName);
}
?>
which I usually import on to other php page like this
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/core/include/db.php";
?>
and works fine. I can start querying using $databaseLink
. But there is one page where its not working. But if I explicitly define the connection like this $databaseLink= mysqli_connect("localhost", "root", "password", "test");
it works. There are other php files in the same directory which has no issues.
I have tried
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/core/include/db.php";
global($databaseLink);
?>
But that does not seem to work too. I have looked it up online for examples but can find any help.
Upvotes: 0
Views: 55
Reputation: 1329
You can simply use include at the top of your php code to link in another php page.
include '/core/include/db.php';
Upvotes: 0