/**
  * Prepare driver before mount volume.
  * Connect to db, check required tables and fetch root path
  *
  * @return bool
  * @author Dmitry (dio) Levashov
  **/
 protected function init()
 {
     if (!($this->options['host'] || $this->options['socket']) || !$this->options['user'] || !$this->options['pass'] || !$this->options['db'] || !$this->options['path'] || !$this->options['files_table']) {
         return false;
     }
     $this->db = new mysqli($this->options['host'], $this->options['user'], $this->options['pass'], $this->options['db'], $this->options['port'], $this->options['socket']);
     if ($this->db->connect_error || @mysqli_connect_error()) {
         return false;
     }
     $this->rootparameter($this->options['alias'], $this->options['defaults']['read'], $this->options['defaults']['write'], $this->options['defaults']['locked'], $this->options['defaults']['hidden']);
     $this->db->set_charset('utf8');
     if ($res = $this->db->query('SHOW TABLES')) {
         while ($row = $res->fetch_array()) {
             if ($row[0] == $this->options['files_table']) {
                 $this->tbf = $this->options['files_table'];
                 break;
             }
         }
     }
     if (!$this->tbf) {
         return false;
     }
     $this->updateCache($this->options['path'], $this->_stat($this->options['path']));
     return true;
 }
Exemplo n.º 2
0
 /**
  * Prepare driver before mount volume.
  * Connect to db, check required tables and fetch root path
  *
  * @return bool
  * @author Dmitry (dio) Levashov
  **/
 protected function init()
 {
     if (!($this->options['host'] || $this->options['socket']) || !$this->options['user'] || !$this->options['db'] || !$this->options['path'] || !$this->options['files_table']) {
         return false;
     }
     $this->db = new mysqli($this->options['host'], $this->options['user'], $this->options['pass'], $this->options['db'], $this->options['port'], $this->options['socket']);
     if ($this->db->connect_error || @mysqli_connect_error()) {
         echo mysql_error();
         exit;
         //return false;
     } else {
         //print_r($this->db);exit;
     }
     $this->db->set_charset('utf8');
     if ($res = $this->db->query('SHOW TABLES')) {
         while ($row = $res->fetch_array()) {
             if ($row[0] == $this->options['files_table']) {
                 $this->tbf = $this->options['files_table'];
                 break;
             }
         }
     }
     if (!$this->tbf) {
         return false;
     }
     $this->updateCache($this->options['path'], $this->_stat($this->options['path']));
     return true;
 }
Exemplo n.º 3
0
 static function connect($host = 'localhost', $user, $password, $name = 'lychee')
 {
     # Check dependencies
     Module::dependencies(isset($host, $user, $password, $name));
     $database = new mysqli($host, $user, $password);
     # Check connection
     if ($database->connect_errno) {
         exit('Error: ' . $database->connect_error);
     }
     # Avoid sql injection on older MySQL versions by using GBK
     if ($database->server_version < 50500) {
         @$database->set_charset('GBK');
     } else {
         @$database->set_charset('utf8');
     }
     # Set unicode
     $database->query('SET NAMES utf8;');
     # Check database
     if (!$database->select_db($name)) {
         if (!Database::createDatabase($database, $name)) {
             exit('Error: Could not create database!');
         }
     }
     # Check tables
     $query = Database::prepare($database, 'SELECT * FROM ?, ?, ?, ? LIMIT 0', array(LYCHEE_TABLE_PHOTOS, LYCHEE_TABLE_ALBUMS, LYCHEE_TABLE_SETTINGS, LYCHEE_TABLE_LOG));
     if (!$database->query($query)) {
         if (!Database::createTables($database)) {
             exit('Error: Could not create tables!');
         }
     }
     return $database;
 }
Exemplo n.º 4
0
 /**
  * connect to the database
  *
  * @param bool $selectdb select the database now?
  * @return bool successful?
  */
 public function connect($selectdb = true)
 {
     if (!extension_loaded('mysqli')) {
         trigger_error('notrace:mysqli extension not loaded', E_USER_ERROR);
         return false;
     }
     $this->allowWebChanges = $_SERVER['REQUEST_METHOD'] !== 'GET';
     if ($selectdb) {
         $dbname = constant('XOOPS_DB_NAME');
     } else {
         $dbname = '';
     }
     if (XOOPS_DB_PCONNECT == 1) {
         $this->conn = new mysqli('p:' . XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, $dbname);
     } else {
         $this->conn = new mysqli(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, $dbname);
     }
     // errno is 0 if connect was successful
     if (0 !== $this->conn->connect_errno) {
         return false;
     }
     if (defined('XOOPS_DB_CHARSET') && '' !== XOOPS_DB_CHARSET) {
         // $this->queryF("SET NAMES '" . XOOPS_DB_CHARSET . "'");
         $this->conn->set_charset(XOOPS_DB_CHARSET);
     }
     $this->queryF('SET SQL_BIG_SELECTS = 1');
     return true;
 }
Exemplo n.º 5
0
 /**
  * Инициализация соединения с БД.
  *
  */
 public static function Init()
 {
     //  Initcializatciia ob``ekta mysqli
     /* create a connection object which is not connected */
     try {
         self::$DB = mysqli_connect(DB_HOST, DB_LOGIN, DB_PASSWORD, DB_NAME);
     } catch (Exception $e) {
         throw new Exception(mysqli_connect_error(), 500);
     }
     /* check connection */
     if (mysqli_connect_errno()) {
         die("mysqli - Unable to connect to the server or choose a database.<br>\n Cause: " . mysqli_connect_error());
     }
     self::$DB->set_charset('utf8');
     //  self::$DB = mysqli_init();
     /* set connection options */
     //  self::$DB->options(MYSQLI_INIT_COMMAND, "SET AUTOCOMMIT=1");
     //  self::$DB->options(MYSQLI_INIT_COMMAND, "SET CacheDataACTER SET UTF8");
     //  self::$DB->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
     /* connect to server */
     //  self::$DB->real_connect(DB_HOST, DB_LOGIN, DB_PASSW, DB_NAME);
     //  self::$DB->select_db(DB_NAME);
     //  Initcializatciia interfesa dlia raboty` s khranimy`mi protcedurami
     //    self::$Procedure = new DB_Procedure();
     //  mysql_query('SET CacheDataACTER SET UTF8');
     //  mysql_query('SET CacheDataACTER SET cp1251_koi8');
     //  mysql_query('set names cp1251');
     //  mysql_query("SET CacheDataACTER SET DEFAULT", self::$DB_Link);
 }
Exemplo n.º 6
0
 private function __construct()
 {
     if (!class_exists('mysqli')) {
         emMsg('服务器空间PHP不支持MySqli函数');
     }
     @($this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWD, DB_NAME));
     if ($this->conn->connect_error) {
         switch ($this->conn->connect_errno) {
             case 1044:
             case 1045:
                 emMsg("连接数据库失败,数据库用户名或密码错误");
                 break;
             case 1049:
                 emMsg("连接数据库失败,未找到您填写的数据库");
                 break;
             case 2003:
                 emMsg("连接数据库失败,数据库端口错误");
                 break;
             case 2005:
                 emMsg("连接数据库失败,数据库地址错误或者数据库服务器不可用");
                 break;
             case 2006:
                 emMsg("连接数据库失败,数据库服务器不可用");
                 break;
             default:
                 emMsg("连接数据库失败,请检查数据库信息。错误编号:" . $this->conn->connect_errno);
                 break;
         }
     }
     $this->conn->set_charset('utf8');
 }
Exemplo n.º 7
0
 /**
  * @param array  $params
  * @param string $username
  * @param string $password
  * @param array  $driverOptions
  *
  * @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException
  */
 public function __construct(array $params, $username, $password, array $driverOptions = array())
 {
     $port = isset($params['port']) ? $params['port'] : ini_get('mysqli.default_port');
     // Fallback to default MySQL port if not given.
     if (!$port) {
         $port = 3306;
     }
     $socket = isset($params['unix_socket']) ? $params['unix_socket'] : ini_get('mysqli.default_socket');
     $dbname = isset($params['dbname']) ? $params['dbname'] : null;
     $flags = isset($driverOptions[static::OPTION_FLAGS]) ? $driverOptions[static::OPTION_FLAGS] : null;
     $this->_conn = mysqli_init();
     $this->setDriverOptions($driverOptions);
     $previousHandler = set_error_handler(function () {
     });
     if (!$this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) {
         set_error_handler($previousHandler);
         $sqlState = 'HY000';
         if (@$this->_conn->sqlstate) {
             $sqlState = $this->_conn->sqlstate;
         }
         throw new MysqliException($this->_conn->connect_error, $sqlState, $this->_conn->connect_errno);
     }
     set_error_handler($previousHandler);
     if (isset($params['charset'])) {
         $this->_conn->set_charset($params['charset']);
     }
 }
Exemplo n.º 8
0
 /**
  * Connects to database.
  *
  * @param string $host
  * @param string $name
  * @param string $password
  * @param integer|null $port
  * @throws \RuntimeException
  */
 public function connect($host, $name, $password, $port = null)
 {
     $this->conn = @new \mysqli($host, $name, $password, $port);
     if (mysqli_connect_error() !== null) {
         throw new \RuntimeException('Cannot connect to database.');
     }
     $this->conn->set_charset('utf8');
 }
Exemplo n.º 9
0
 /**
  * @param string $host What server is the database located on?
  * @param string $user What is the DB user
  * @param string $pass What is her password
  * @param string $database What is the name of the database that we want to query
  * @param int $port What port should we connect to
  *
  * @throws Exception
  */
 public function __construct($host, $user, $pass, $database, $port = 3306)
 {
     $this->mysqli = new mysqli($host, $user, $pass, $database, $port);
     $this->mysqli->set_charset("utf8");
     if ($this->mysqli->connect_errno) {
         throw new Exception("Failed to connect to MySQL: (" . $this->mysqli->connect_errno . ") " . $this->mysqli->connect_error);
     }
 }
Exemplo n.º 10
0
 public function __construct(array $params, $username, $password, array $driverOptions = array())
 {
     $port = isset($params['port']) ? $params['port'] : ini_get('mysqli.default_port');
     $socket = isset($params['unix_socket']) ? $params['unix_socket'] : ini_get('mysqli.default_socket');
     $this->_conn = new \mysqli($params['host'], $username, $password, $params['dbname'], $port, $socket);
     if (isset($params['charset'])) {
         $this->_conn->set_charset($params['charset']);
     }
 }
Exemplo n.º 11
0
 /**
  * Establishes db connection
  */
 private function connect($host, $user, $pwd, $dbname)
 {
     $this->database = mysqli_init();
     $this->database->real_connect($host, $user, $pwd, $dbname);
     if ($this->database === NULL || $this->database->connect_errno) {
         die("Failed to connect to database!");
     }
     $this->database->set_charset("utf8");
 }
Exemplo n.º 12
0
 /**
  * Vérifie si la connection à la base de donnée est ouverte, la créer sinon
  */
 private static function isOpen()
 {
     if (self::$oMysqli == NULL) {
         $aDbConfig = Config::get('db');
         self::$oMysqli = new mysqli($aDbConfig['hostname'], $aDbConfig['username'], $aDbConfig['password'], $aDbConfig['name']);
         self::$oMysqli->set_charset("utf8");
     }
     return true;
 }
Exemplo n.º 13
0
 function __construct($host, $user, $password, $name = false)
 {
     if ($name) {
         $this->conn = new \mysqli($host, $user, $password, $name);
         $this->conn->set_charset('utf8');
     } else {
         $this->conn = new \mysqli($host, $user, $password);
     }
 }
Exemplo n.º 14
0
 /**
  * @param string $host
  * @param string $username
  * @param string $password
  * @param string $db
  * @param int $port
  */
 public function __construct($host, $username, $password, $db, $port = NULL)
 {
     if ($port == NULL) {
         $port = ini_get('mysqli.default_port');
     }
     $this->_mysqli = new mysqli($host, $username, $password, $db, $port) or die('Shrinkwrap could not connect to the pool');
     $this->_mysqli->set_charset('utf8');
     self::$_instance = $this;
 }
Exemplo n.º 15
0
 protected function __init()
 {
     Config::_getInstance()->load('DB');
     $this->link = new mysqli(config('host', 'DB'), config('user', 'DB'), config('password', 'DB'), config('db', 'DB'));
     if ($this->link->connect_error) {
         $this->addError('connection', $this->link->connect_errno, $this->link->connect_error);
     }
     $this->link->set_charset(config('encoding', 'DB'));
 }
Exemplo n.º 16
0
 /**
  * @param string $host
  * @param string $username
  * @param string $password
  * @param string $db
  * @param int $port
  */
 public function __construct($host, $username, $password, $db, $port = NULL)
 {
     if ($port == NULL) {
         $port = ini_get('mysqli.default_port');
     }
     $this->_mysqli = new mysqli($host, $username, $password, $db, $port) or die('There was a problem connecting to the database');
     $this->_mysqli->set_charset('utf8');
     self::$_instance = $this;
 }
Exemplo n.º 17
0
 public function __construct($host = RUDE_DATABASE_HOST, $user = RUDE_DATABASE_USER, $pass = RUDE_DATABASE_PASS, $name = RUDE_DATABASE_NAME)
 {
     $this->mysqli = new \mysqli($host, $user, $pass, $name);
     if ($this->mysqli->connect_errno) {
         debug($this->mysqli->connect_errno);
     }
     if (!$this->mysqli->set_charset("utf8")) {
         debug($this->mysqli->connect_errno);
     }
 }
Exemplo n.º 18
0
 /**
  * MySQLi constructor.
  *
  * @param string $hostname
  * @param string $username
  * @param string $password
  * @param string $database
  * @param string $port
  */
 public function __construct($hostname, $username, $password, $database, $port = '3306')
 {
     $this->link = new \mysqli($hostname, $username, $password, $database, $port);
     if ($this->link->connect_error) {
         trigger_error('Error: Could not make a database link (' . $this->link->connect_errno . ') ' . $this->link->connect_error);
         exit;
     }
     $this->link->set_charset("utf8");
     $this->link->query("SET SQL_MODE = ''");
 }
Exemplo n.º 19
0
 /**
  * Подключение к СУБД методом <code>mysqli::__construct()</code>.
  * 
  * @return void
  * @access public
  * @static
  */
 public static function open()
 {
     if (static::$rdbmsconn) {
         return;
     }
     $driver = new \mysqli_driver();
     $driver->report_mode = \MYSQLI_REPORT_ERROR | \MYSQLI_REPORT_STRICT;
     static::$rdbmsconn = new \mysqli(Config::$mysql_host, Config::$mysql_user, Config::$mysql_pass, Config::$mysql_base, Config::$mysql_port, Config::$mysql_sock);
     static::$rdbmsconn->set_charset(Config::$mysql_cset);
 }
Exemplo n.º 20
0
 public function &connect($a_address, $a_user = '', $a_pass = '')
 {
     $connection = new mysqli($a_address, $a_user, $a_pass);
     if ($connection && !mysqli_connect_errno()) {
         $this->setConnection($connection);
         $this->m_connection->set_charset('utf8');
     } else {
         throw new Zoombi_Exception_DatabaseAdapter(mysqli_connect_error(), mysqli_connect_errno());
     }
     return $this;
 }
Exemplo n.º 21
0
 protected function __construct($host, $username, $password, $database, $table)
 {
     $this->table = $table;
     $this->connection = new \mysqli($host, $username, $password, $database);
     $this->connection->set_charset("utf8");
     if ($this->connection->errno) {
         throw new \Exception('mysqlli error: ' . $this->connection->error);
     }
     //registering autoloading of viewModel
     spl_autoload_register([$this, 'loadViewModel']);
 }
Exemplo n.º 22
0
 /**
  * MySQLi connector
  * 
  * @param string $host
  * @param string $name
  * @param string $pass
  * @param string $db
  * @param string $charset
  * @return mysqli|string
  */
 private function _connect($host = 'localhost', $name = 'root', $pass = '', $db = '', $charset = 'utf8')
 {
     $this->_resource = new mysqli($host, $name, $pass, $db);
     if (!$this->_resource || $this->_resource->connect_error) {
         return Helper_View::message(Language::get('sql_connect_false') . '<br/>' . htmlspecialchars($this->_resource->connect_error, ENT_NOQUOTES), Helper_View::MESSAGE_ERROR);
     }
     if ($charset) {
         $this->_resource->set_charset($charset);
     }
     return $this->_resource;
 }
Exemplo n.º 23
0
 /**
  * Реализация установки соединения с базой
  * @throws Exception
  */
 protected function realConnect()
 {
     $this->db = @new \mysqli(!empty($this->config['hostname']) ? 'p:' . $this->config['hostname'] : '', $this->config['username'], $this->config['password']);
     if ($this->db->connect_error) {
         throw new Exception($this->error = $this->db->connect_error);
     }
     $this->db->set_charset('utf8');
     if (!$this->db->select_db($this->config['database'])) {
         throw new Exception($this->error = $this->db->error);
     }
 }
Exemplo n.º 24
0
 /**
  * Открывает соединение с базой данных. Метод возвращает "true" при успешном открытии соединения или "false" при ошибке.
  * @param string    $host       Сервер (хост) базы данных.
  * @param string    $db         Имя базы данных.
  * @param string    $login      Логин.
  * @param string    $password   Пароль.
  * @return boolean
  */
 function Connect($host, $db, $login, $password)
 {
     debug("TDataBase.connect: Connect to '{$db}' at '{$host}'");
     $this->db = new mysqli($host, $login, $password, $db);
     if ($this->db->connect_errno) {
         $this->error = $this->db->connect_error;
         return false;
     }
     $this->db->set_charset($password);
     return true;
 }
Exemplo n.º 25
0
 public function __construct(array $params, $username, $password, array $driverOptions = array())
 {
     $port = isset($params['port']) ? $params['port'] : ini_get('mysqli.default_port');
     $socket = isset($params['unix_socket']) ? $params['unix_socket'] : ini_get('mysqli.default_socket');
     $this->_conn = mysqli_init();
     if (!$this->_conn->real_connect($params['host'], $username, $password, $params['dbname'], $port, $socket)) {
         throw new MysqliException($this->_conn->connect_error, $this->_conn->connect_errno);
     }
     if (isset($params['charset'])) {
         $this->_conn->set_charset($params['charset']);
     }
 }
Exemplo n.º 26
0
 /** begins the MySQL connection
  * @param bool $create_db
  * @throws DBMySQLException
  */
 private function init_mysql_connect($create_db = FALSE)
 {
     $this->connect = new mysqli($this->host, $this->user, $this->pass, NULL, $this->port);
     if ($this->connect->connect_errno > 0) {
         throw new DBMySQLException('Unable to connect to MySQL server reason: ' . $this->connect->connect_error, 1);
     }
     $this->connect->set_charset($this->encoding);
     if ($create_db) {
         $this->connect->query('CREATE DATABASE IF NOT EXISTS ' . $this->format_table_or_database_string($this->db_name));
     }
     $this->connect->select_db($this->db_name);
 }
Exemplo n.º 27
0
 /**
  * This function is delayed constructor. This is because constructor is called during
  * application initialization when configuration file is red.
  * @param array $init
  * @return bool
  */
 public function init($init)
 {
     $this->conn = @new \mysqli($init['server'], $init['user'], $init['password'], $init['database']);
     $this->table = $init['table'];
     //no error
     if ($this->conn->connect_errno === 0) {
         $this->conn->set_charset('utf8');
     } else {
         return false;
     }
     return true;
 }
Exemplo n.º 28
0
 public function connect()
 {
     $this->mysqli = @new \mysqli($this->config['server'], $this->config['user'], $this->config['password'], $this->config['database'], $this->config['port']);
     if ($this->mysqli->connect_error) {
         throw new DBException('SQL connection error (' . $this->mysqli->connect_errno . '): ' . $this->mysqli->connect_error);
     }
     if ($this->config['charset']) {
         if (!$this->mysqli->set_charset($this->config['charset'])) {
             throw new DBException('SQL charset error (' . $this->mysqli->errno . '): ' . $this->mysqli->error);
         }
     }
     $this->connected = true;
 }
Exemplo n.º 29
0
 /**
  * @return Recipe_Database_MySQLi
  * @throws Recipe_Exception_Generic
  */
 protected function connect()
 {
     try {
         $this->mysqli = new mysqli($this->host, $this->user, $this->password, $this->database, $this->port);
         $this->mysqli->set_charset("utf8");
     } catch (Exception $e) {
         die("Unable to connect to database. Please try again later.");
     }
     if (mysqli_connect_errno()) {
         die("Connection to database failed: " . mysqli_connect_error());
     }
     return $this;
 }
Exemplo n.º 30
0
 private function __construct()
 {
     /**
      * Object of Settings class
      * @var Settings
      */
     $registry = Registry::getInstance();
     $this->db_config = $registry->getValue('db_config');
     $this->connection = new \mysqli($this->db_config['db_host'], $this->db_config['db_user'], $this->db_config['db_password'], $this->db_config['db_name']);
     if ($this->connection->connect_error) {
         die($this->connection->connect_error);
     }
     $this->connection->set_charset('utf8');
 }