almeno il codice ordinato...
codice:define("DB_HOST", "localhost"); define("DB_USER", "root"); define("DB_PASS", ""); define("DB_NAME", "test"); define("DB_CACHE_TIME", 0); define("TABLE_PREFIX", "rc_"); define("DB_ERROR_MAIL", ""); define("DB_PORT", "3306"); define("PCONNECT", false); if (!empty($db_host)) { $db_host = ''; } else { $db_host = DB_HOST; } if (!empty($db_user)) { $db_user = ''; } else { $db_user = DB_USER; } if (!empty($db_pass)) { $db_pass = ''; } else { $db_pass = DB_PASS; } if (!empty($db_name)) { $db_name = ''; } else { $db_name = DB_NAME; } if (!empty($db_cache_time)) { $db_cache_time = ''; } else { $db_cache_time = DB_CACHE_TIME; }codice:<? class DataBase { public $dbhost = ""; public $dbuser = ""; public $dbpass = ""; public $dbname = ""; public $db_cache_time = 0; public $connect = ""; public $query = ""; public $dbport = ""; function DataBase() { if (defined("DB_HOST")) { $this->dbhost = DB_HOST; } if (defined("DB_USER")) { $this->dbuser = DB_USER; } if (defined("DB_PASS")) { $this->dbpass = DB_PASS; } if (defined("DB_NAME")) { $this->dbname = DB_NAME; } if (defined("DB_PORT")) { $this->dbport = DB_PORT; } } function __construct() { global $db_host, $db_user, $db_pass, $db_name, $db_cache_time; $this->dbhost = $db_host; $this->dbuser = $db_user; $this->dbpass = $db_pass; $this->dbname = $db_name; $this->db_cache_time = $db_cache_time; } function connect() { global $db_host, $db_user, $db_pass, $db_name, $db_cache_time; $this->query = new mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname) or die($this->connect_error); if ($this->query == true) { return true; } else { return false; } } function dberror() { if ($this->query) { return $this->connect_error($this->query); } return $this->connect_error(); }} $con = new DataBase(); echo '<pre>'; var_dump($con->connect()); echo '</pre>'; echo '<pre>'; print_r($con->dberror()); echo '</pre>';


Rispondi quotando