I am learning the object oriented PHP. Now I have the mission to get a connection. I'd like to show my code and ask you for some optimization support. Maybe there are several absolutely wrong understood things. I don't hope so. I want to improve my design. In real the Constants of course have the rights values. BIG THANKS! :)
// index.php
<?php
require( dirname( __FILE__ ) . '/config.php' );
new db(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
?>
// config.php
<?php
define('DB_HOST', 'host');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');
define('DB_DATABASE', 'database');
if (!defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . '/includes/classes/db.class.php');
?>
// db.class.php
<?php
class db
{
protected $db_host;
protected $db_user;
protected $db_password;
protected $db_name;
function __construct($dbHost, $dbUser, $dbPassword, $dbName)
{
global $mysqli;
$this -> db_host = $dbHost;
$this -> db_user = $dbUser;
$this -> db_password = $dbPassword;
$this -> db_name = $dbName;
$this -> mysqli = new mysqli($this -> db_host, $this -> db_user, $this -> db_password, $this -> db_name);
$mysqli = $this -> mysqli;
}
}
?>