config.php
<?php
class Config {
// Config variables
public $_host = "host"; // eg. localhost
public $_username = "username";
public $_password = "password";
public $_dbname = "dbname"; // Database name
// Constructor
public function __construct(){
}
}
?>
index.php
<?php
// Include config class file
include("config.php");
// Create config class
$config = new Config();
// Create connection
$con = mysqli_connect($config->_host, $config->_username, $config->_password, $config->_dbname);
// Check connection
if (mysqli_connect_errno($con))
die("Failed to connect to MySQL: " . mysqli_connect_error());
echo "MySQL successfully connected!"
?>
No comments:
Post a Comment