Welcome aboard! We are happy you are here and wish you good net-raft!
// this php code put into connectDB.php
<?php
require_once ("/Includes/myconnectiondata.php");
// Create database connection
$databaseConnection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($databaseConnection->connect_error)
{
die("Database selection failed: " . $databaseConnection->connect_error);
}
?>
// this php code put into myconnectiondata.php
<?php
define('DB_NAME', 'xxx');
define('DB_USER', 'xxx');
define('DB_PASSWORD', 'xxx');
define('DB_HOST', 'localhost');
?>
This put into index.php
<?php
require_once ("/Includes/myconnectiondata.php");
global $databaseConnection;
create_tables($databaseConnection);
function create_tables($databaseConnection)
{
$query_users = "here put your sql statement";
$databaseConnection->query($query_users);
}
?>
// this works fine
// index.php
<?php
require_once ("/Includes/connectDB.php");
?>
// connectDB.php
<?php
require_once ("/Includes/myconnectiondata.php");
// Create database connection
$databaseConnection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($databaseConnection->connect_error)
{
die("Database selection failed: " . $databaseConnection->connect_error);
}
else
{
echo "connected!";
}
?>
// myconnectiondata.php
<?php
define('DB_NAME', 'xxx');
define('DB_USER', 'xxx');
define('DB_PASSWORD', 'xxx');
define('DB_HOST', 'localhost');
?>
The most helpful PHP solutions
detect browser phpPHP Click to see more ... 4.6K 408