Answer the question
In order to leave comments, you need to log in
How to exclude file connection?
Hello, there is a class for working with a database
<?php
namespace model;
include_once 'config.php';
class Database
{
private $host = HOST;
private $user = USER;
private $pass = PASS;
private $database = DATABASE;
private $db = NULL;
private $sl = NULL;
public $result = NULL;
public $query = NULL;
public function __construct()
{
$this->db = new mysqli(HOST, USER, PASS, DATABASE);
if(!$this->db){
echo "Невозможно установить соединение с базой данных<br/>Код ошибки:<br/>";
exit(mysql_error());
}
else
{
mysqli_set_charset($this->db, 'utf8');
}
}
}
define('DIRSEP', DIRECTORY_SEPARATOR);
function __autoload($class_name) {
$class_peaces = explode('\\', $class_name);
switch ($class_peaces[0]) {
case 'model':
$dirpath = ROOT . DIRSEP . implode(DIRSEP, $class_peaces) . '.php';
require_once $dirpath;
break;
}
}
$db = new model\Database();
Warning: require_once(W:/domains/testPHPoop\model\mysqli.php): failed to open stream: No such file or directory in W:\domains\testPHPoop\functions.php on line 15
Fatal error: require_once(): Failed opening required 'W:/domains/testPHPoop\model\mysqli.php' (include_path='.;w:/modules/php/PHP-5.4;w:/modules/php/PHP-5.4/PEAR/pear') in W:\domains\testPHPoop\functions.php on line 15
Answer the question
In order to leave comments, you need to log in
$this->db = new \mysqli(HOST, USER, PASS, DATABASE);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question