public function isInstalled()
 {
     if (!$this->isConfigured() or !$this->db) {
         return FALSE;
     }
     try {
         if (!$this->db->isConnected()) {
             mysqli_report(MYSQLI_REPORT_ALL);
             $this->db->connect(FALSE);
         }
     } catch (ServiceException $e) {
         return FALSE;
     }
     if (!$this->db->databaseExists()) {
         return FALSE;
     }
     try {
         $this->db->selectDb();
     } catch (ServiceException $e) {
         Logging::logDebug('Mollify not installed');
         return FALSE;
     }
     try {
         $ver = $this->dbUtil->installedVersion();
     } catch (ServiceException $e) {
         Logging::logDebug('Mollify not installed');
         return FALSE;
     }
     if ($ver != NULL) {
         Logging::logDebug('Mollify installed version: ' . $ver);
     } else {
         Logging::logDebug('Mollify not installed');
     }
     return $ver != NULL;
 }
Пример #2
0
 public function __construct($charset, $handler = null)
 {
     \mysqli_report(MYSQLI_REPORT_OFF);
     $this->charset = $charset;
     $this->connection = null;
     $this->handler = $handler;
 }
Пример #3
0
 public static function Init($sServer, $sUser, $sPwd, $sSource = '')
 {
     self::$m_sDBHost = $sServer;
     self::$m_sDBUser = $sUser;
     self::$m_sDBPwd = $sPwd;
     self::$m_sDBName = $sSource;
     self::$m_oMysqli = null;
     mysqli_report(MYSQLI_REPORT_STRICT);
     // *some* errors (like connection errors) will throw mysqli_sql_exception instead
     // of generating warnings printed to the output but some other errors will still
     // cause the query() method to return false !!!
     try {
         $aConnectInfo = explode(':', self::$m_sDBHost);
         if (count($aConnectInfo) > 1) {
             // Override the default port
             $sServer = $aConnectInfo[0];
             $iPort = (int) $aConnectInfo[1];
             self::$m_oMysqli = new mysqli($sServer, self::$m_sDBUser, self::$m_sDBPwd, '', $iPort);
         } else {
             self::$m_oMysqli = new mysqli(self::$m_sDBHost, self::$m_sDBUser, self::$m_sDBPwd);
         }
     } catch (mysqli_sql_exception $e) {
         throw new MySQLException('Could not connect to the DB server', array('host' => self::$m_sDBHost, 'user' => self::$m_sDBUser), $e);
     }
     if (!empty($sSource)) {
         try {
             mysqli_report(MYSQLI_REPORT_STRICT);
             // Errors, in the next query, will throw mysqli_sql_exception
             self::$m_oMysqli->query("USE `{$sSource}`");
         } catch (mysqli_sql_exception $e) {
             throw new MySQLException('Could not select DB', array('host' => self::$m_sDBHost, 'user' => self::$m_sDBUser, 'db_name' => self::$m_sDBName), $e);
         }
     }
 }
Пример #4
0
 static function initialise($ConfigFile)
 {
     if ($initialised) {
         return;
     }
     // Run this only once!
     include $ConfigFile;
     $host = $conf['database_host'];
     $db = $conf['database_name'];
     $user = $conf['database_login'];
     $pass = $conf['database_pass'];
     CSession::$session_timeout = $conf['session_timeout_sec'];
     // connect to mysql and open database
     CSession::$db_link = mysql_connect($host, $user, $pass) or die("Couldn't connect to the database");
     @mysql_select_db($db, CSession::$db_link) or die("Unable to select database");
     // // Create a db connection using PDO. Should migrate everything over to use PDO.
     // CSession::$pdo_dbh = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
     // Connection using mysqli for the newer code. Should move all mysql code to mysqli!
     mysqli_report(MYSQLI_REPORT_STRICT);
     try {
         CSession::$dbh = new mysqli($host, $user, $pass, $db);
         if (CSession::$dbh->connect_errno) {
             die("FAILED TO CONNECT TO THE DB. ERROR: " . CSession::$dbh->connect_error);
             exit;
         }
     } catch (mysqli_sql_exception $e) {
         die("FAILED TO CONNECT TO THE DB. ERROR: " . $e->getMessage());
     }
 }
Пример #5
0
 /**
  * Выполнение запроса к базе данных, выполняет коннект на запросе
  *
  * @param string $query
  * @param array $params
  * @param int $shard_id
  * @throws Exception
  */
 public static function query($query, array $params = [], $shard_id = 0)
 {
     assert("is_string(\$query)");
     assert("\\is_array(\$params)");
     assert("is_int(\$shard_id)");
     assert("\$shard_id >= 0 && \$shard_id < 4096 /* only 4096 shards allowed */");
     static $time = 0;
     if (!static::$shards) {
         static::$shards = config('mysql.shard');
     }
     if (!static::$pool) {
         mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
     }
     if (!isset(static::$shards[$shard_id])) {
         trigger_error('No shards for mysql server specified');
     }
     // Если на этом шарде еще коннетка нет
     if (!isset(static::$pool[$shard_id])) {
         $dsn =& static::$shards[$shard_id];
         $dsn_key = function ($key) use($dsn) {
             preg_match("|{$key}=([^;]+)|", $dsn, $m);
             return $m ? $m[1] : null;
         };
         $DB =& static::$pool[$shard_id];
         $DB = mysqli_init();
         $DB->options(MYSQLI_OPT_CONNECT_TIMEOUT, config('mysql.connect_timeout'));
         $DB->real_connect($dsn_key('host'), $dsn_key('user'), $dsn_key('password'), $dsn_key('dbname'), $dsn_key('port'));
     }
     $DB =& static::$pool[$shard_id];
     if (range(0, sizeof($params) - 1) === array_keys($params)) {
         $query = preg_replace_callback('|\\?|', function () {
             static $count = 0;
             return ':' . $count++;
         }, $query);
     }
     $params = array_combine(array_map(function ($k) {
         return ':' . $k;
     }, array_keys($params)), array_map(function ($item) use($DB) {
         return filter_var($item, FILTER_VALIDATE_INT | FILTER_VALIDATE_FLOAT | FILTER_VALIDATE_BOOLEAN) ? $item : '"' . $DB->real_escape_string($item) . '"';
     }, $params));
     $Result = $DB->query(strtr($query, $params));
     // Определяем результат работы функции в зависимости от типа запроса к базе
     switch (strtolower(strtok($query, ' '))) {
         case 'insert':
             return $DB->insert_id ?: $DB->affected_rows;
             break;
         case 'update':
         case 'delete':
             return $DB->affected_rows;
             break;
         case 'select':
         case 'describe':
             $result = $Result->fetch_all(MYSQLI_ASSOC);
             $Result->close();
             return $result;
             break;
         default:
             trigger_error('Undefined call for database query');
     }
 }
Пример #6
0
 /**
  * Create a new Mysqli object.
  *
  * @param array $params
  * @return object
  */
 public function __construct($key)
 {
     mysqli_report(MYSQLI_REPORT_STRICT);
     $params = Config::get('mysql.' . $key);
     if ($params === null && IS_SUBSITE) {
         $params = MainConfig::get('mysql.' . $key);
     }
     if ($params === null) {
         $params = [];
     }
     parent::init();
     $params['pass'] = isset($params['pass']) ? $params['pass'] : '';
     $params['user'] = isset($params['user']) ? $params['user'] : '******';
     $params['host'] = isset($params['host']) ? $params['host'] : '127.0.0.1';
     $params['port'] = isset($params['port']) ? $params['port'] : 3306;
     $params['timeout'] = isset($params['timeout']) ? $params['timeout'] : 30;
     $params['charset'] = isset($params['charset']) ? $params['charset'] : 'utf8';
     $params['database'] = isset($params['database']) ? $params['database'] : false;
     parent::options(MYSQLI_OPT_CONNECT_TIMEOUT, $params['timeout']);
     parent::real_connect($params['host'], $params['user'], $params['pass'], $params['database'], $params['port']);
     if ($this->errno === 0) {
         $this->set_charset($params['charset']);
         if (isset($params['cache']) && $params['cache'] === false) {
             $this->cache(false);
         }
     }
 }
Пример #7
0
 public function __construct($host, $user, $pass, $dbname, $charset = "utf8", $debug = true, $errormsg = "Database connection failed.")
 {
     //if debugging errors show error report
     if ($this->debug) {
         mysqli_report(MYSQLI_REPORT_ERROR);
     } else {
         mysqli_report(MYSQLI_REPORT_OFF);
     }
     //making connection
     $this->connection = @new mysqli($host, $user, $pass, $dbname);
     //if conn error populating property conn_error with the results of connect_error function
     $this->connection_error = $this->connection->connect_error;
     $this->connection_error_code = $this->connection->connect_errno;
     $this->debug = $debug;
     if (!$this->connection_error_code) {
         $this->connection->set_charset($charset);
         if ($charset == "utf8") {
             $this->connection->query("SET NAMES utf8");
         }
         $this->server_info = $this->connection->server_info;
         $this->client_info = $this->connection->client_info;
         $this->host_info = $this->connection->host_info;
     } else {
         if ($this->connection_error_code && $errormsg !== false) {
             error_log("MySQL database error:  " . $this->connection_error . " for error code " . $this->connection_error_code);
             if ($this->debug) {
                 die("Database Connection Error " . $this->connection_error_code . ": " . $this->connection_error);
             } else {
                 die($errormsg);
             }
         }
     }
 }
Пример #8
0
 function __construct()
 {
     $tables = null;
     if (!defined(GODTABLE) || !defined(PHANETONTABLE) || !defined(ITEMTABLE) || !defined(BUILDTABLE) || !defined(SKILLTABLE) || !defined(BUILDLVLTABLE) || !defined(BUILDITEMTABLE) || !defined(EFFECTITEMTABLE)) {
         $tables = array(GODTABLE, PHANETONTABLE, ITEMTABLE, BUILDTABLE, SKILLTABLE, BUILDLVLTABLE, BUILDITEMTABLE, EFFECTITEMTABLE);
     } else {
         $this->insertIntoArray(Database::$error_array['defNotSet']);
     }
     if (!defined(USER_NAME) || !define(USER_PASSWORD) || !defined(DATABASE) || !defined(SERVER_ADDRESS) || !defined(DATABASE_PORT)) {
     } else {
         $this->insertIntoArray(Database::$error_array['dbInfo']);
     }
     mysqli_report(MYSQLI_REPORT_STRICT);
     try {
         $this->connection = new mysqli(SERVER_ADDRESS, USER_NAME, USER_PASSWORD, DATABASE, DATABASE_PORT);
     } catch (Exception $ex) {
         $this->insertIntoArray($ex);
     }
     //$this->setSQLTimezone($this->connection);
     if ($this->connection && $this->connection->connect_error) {
         $this->connection = null;
         $this->insertIntoArray(Database::$error_array['db']);
     }
     if (!empty($tables)) {
         foreach ($tables as $table) {
             if (!empty($table)) {
                 $this->checkIfTableExists($table);
             }
         }
     }
     $this->tables = $this->getTables();
 }
Пример #9
0
 /**
  * connect
  * @access public
  * @param array $config
  * @param integer $linknum
  * @return mixed
  */
 public function connect($config = null, $linknum = 0)
 {
     $config = $this->dbconfig($config, $linknum);
     $linknum = isset($config['linknum']) ? $config['linknum'] : 0;
     if (isset($this->_linkids[$linknum])) {
         return $this->_linkid = $this->_linkids[$linknum];
     }
     if (empty($config['dbname'])) {
         trigger_error('Mysqli DSN configure error', E_USER_ERROR);
         return false;
     }
     $config['host'] = empty($config['host']) ? 'localhost' : $config['host'];
     $config['user'] = empty($config['user']) ? '' : $config['user'];
     $config['pass'] = empty($config['pass']) ? '' : $config['pass'];
     $config['port'] = empty($config['port']) ? 3306 : intval($config['port']);
     $config['charset'] = empty($config['charset']) ? 'utf8' : $config['charset'];
     $this->_linkids[$linknum] = new mysqli($config['host'], $config['user'], $config['pass'], $config['dbname'], $config['port']);
     if (mysqli_connect_errno()) {
         trigger_error(mysqli_connect_error(), E_USER_ERROR);
         return false;
     }
     $dbversion = $this->_linkids[$linknum]->server_version;
     $this->_linkids[$linknum]->query("SET NAMES '{$config['charset']}'");
     if ($dbversion > '5.0.1') {
         $this->_linkids[$linknum]->query("SET sql_mode=''");
     }
     mysqli_report(MYSQLI_REPORT_ERROR);
     return $this->_linkid = $this->_linkids[$linknum];
 }
Пример #10
0
 /**
  * run
  * 
  * @param Event $event
  */
 public static function run(Event $event = null)
 {
     $io = self::getIO($event);
     if (!file_exists($file_path = rtrim(APPPATH, '/') . '/config/database.php')) {
         $io->write('<error>The configuration file database.php does not exist.</error>');
     }
     include $file_path;
     if (!isset($active_group)) {
         $io->write('<error>You have not specified a database connection group via $active_group in your config/database.php file.</error>');
     }
     $hostname = $db[$active_group]['hostname'];
     $username = $db[$active_group]['username'];
     $password = $db[$active_group]['password'];
     $database = $db[$active_group]['database'];
     try {
         mysqli_report(MYSQLI_REPORT_STRICT);
         $mysqli = new \mysqli($hostname, $username, $password);
         $io->write(sprintf('<comment>Connected to %s:%s.</comment> ', $hostname, $database));
         $sql_script_path = $io->ask('<question>Enter your SQl script path :</question> ', null);
         self::execute_script($mysqli, $db[$active_group], $sql_script_path);
         $io->write('<info>The script was executed successfully.</info>');
     } catch (\Exception $e) {
         $io->write('<error>' . $e->getMessage() . '</error>');
     }
 }
Пример #11
0
 public function __construct($database, $host, $user, $password, $charset = "utf8", $debug = true, $errormsg = "Database connection failed.")
 {
     if ($this->debug) {
         mysqli_report(MYSQLI_REPORT_ERROR);
     } else {
         mysqli_report(MYSQLI_REPORT_OFF);
     }
     $this->connection = @new mysqli($host, $user, $password, $database);
     $this->connection_error = $this->connection->connect_error;
     $this->connection_error_code = $this->connection->connect_errno;
     $this->debug = $debug;
     if (!$this->connection_error_code) {
         $this->connection->set_charset($charset);
         if ($charset == "utf8") {
             $this->connection->query("SET NAMES utf8");
         }
         $this->server_info = $this->connection->server_info;
         $this->client_info = $this->connection->client_info;
         $this->host_info = $this->connection->host_info;
     } else {
         if ($this->connection_error_code && $errormsg !== false) {
             error_log("MySQL database error:  " . $this->connection_error . " for error code " . $this->connection_error_code);
             if ($this->debug) {
                 die("Database Connection Error " . $this->connection_error_code . ": " . $this->connection_error);
             } else {
                 die($errormsg);
             }
         }
     }
 }
Пример #12
0
 public function __construct($database, $username = '', $password = '', $server = 'localhost')
 {
     $this->mysqli = new mysqli($server, $username, $password, $database);
     if (mysqli_connect_errno() !== 0) {
         throw new Exception(mysqli_connect_error(), mysqli_connect_errno());
     }
     mysqli_report(MYSQLI_REPORT_ERROR);
 }
Пример #13
0
 /**
  * If the Database timed our for any reason, we protect errors by closing out
  * the socket to the Database through the MySQLi object. Otherwise, this
  * handles connecting to the MySQL database specified in the config file.
  */
 public static function connect()
 {
     self::disconnect();
     //throw errors, but not too many
     mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
     self::$_mysql = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
     self::$_mysql->autocommit(false);
 }
Пример #14
0
 /**
  * Connection constructor.
  *
  * @param $config string[]
  */
 public function __construct($config)
 {
     mysqli_report(MYSQLI_REPORT_STRICT);
     // attempt to connect to the db
     $this->mysqli = new \mysqli($config['host'], $config['user'], $config['password'], $config['database'], $config['port']);
     // we will manually commit our sql changes
     $this->mysqli->autocommit(false);
     $this->statementCache = new Statement(500);
 }
Пример #15
0
 public function connect()
 {
     try {
         mysqli_report(MYSQLI_REPORT_STRICT);
         $this->cnx = new \mysqli(parse_url($this->connectionString, PHP_URL_HOST), parse_url($this->connectionString, PHP_URL_USER), parse_url($this->connectionString, PHP_URL_PASS), parse_url($this->connectionString, PHP_URL_FRAGMENT), parse_url($this->connectionString, PHP_URL_PORT), parse_url($this->connectionString, PHP_URL_PATH));
     } catch (\mysqli_sql_exception $ex) {
         throw new ConnectionFailedException($ex->getMessage(), $ex->getCode(), $ex);
     }
 }
Пример #16
0
 public function __construct()
 {
     $params = (include ROOT . '/config/db_params.php');
     mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
     $this->db = new mysqli($params['host'], $params['user'], $params['password'], $params['dbname']);
     if (mysqli_connect_errno()) {
         exit;
     }
 }
Пример #17
0
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     mysqli_report(MYSQLI_REPORT_OFF);
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         // default values
         $config += array('charset' => 'utf8', 'timezone' => date('P'), 'username' => ini_get('mysqli.default_user'), 'password' => ini_get('mysqli.default_pw'), 'socket' => ini_get('mysqli.default_socket'), 'port' => NULL);
         if (!isset($config['host'])) {
             $host = ini_get('mysqli.default_host');
             if ($host) {
                 $config['host'] = $host;
                 $config['port'] = ini_get('mysqli.default_port');
             } else {
                 $config['host'] = NULL;
                 $config['port'] = NULL;
             }
         }
         $foo =& $config['flags'];
         $foo =& $config['database'];
         $this->connection = mysqli_init();
         if (isset($config['options'])) {
             if (is_scalar($config['options'])) {
                 $config['flags'] = $config['options'];
                 // back compatibility
                 trigger_error(__CLASS__ . ": configuration item 'options' must be array; for constants MYSQLI_CLIENT_* use 'flags'.", E_USER_NOTICE);
             } else {
                 foreach ((array) $config['options'] as $key => $value) {
                     mysqli_options($this->connection, $key, $value);
                 }
             }
         }
         @mysqli_real_connect($this->connection, (empty($config['persistent']) ? '' : 'p:') . $config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $config['socket'], $config['flags']);
         // intentionally @
         if ($errno = mysqli_connect_errno()) {
             throw new DibiDriverException(mysqli_connect_error(), $errno);
         }
     }
     if (isset($config['charset'])) {
         $ok = FALSE;
         if (version_compare(PHP_VERSION, '5.1.5', '>=')) {
             // affects the character set used by mysql_real_escape_string() (was added in MySQL 5.0.7 and PHP 5.0.5, fixed in PHP 5.1.5)
             $ok = @mysqli_set_charset($this->connection, $config['charset']);
             // intentionally @
         }
         if (!$ok) {
             $this->query("SET NAMES '{$config['charset']}'");
         }
     }
     if (isset($config['sqlmode'])) {
         $this->query("SET sql_mode='{$config['sqlmode']}'");
     }
     if (isset($config['timezone'])) {
         $this->query("SET time_zone='{$config['timezone']}'");
     }
     $this->buffered = empty($config['unbuffered']);
 }
Пример #18
0
 function connect($server, $username, $password)
 {
     mysqli_report(MYSQLI_REPORT_OFF);
     // stays between requests, not required since PHP 5.3.4
     list($host, $port) = explode(":", $server, 2);
     // part after : is used for port or socket
     $this->ssl_set(NULL, NULL, NULL, NULL, "AES256-SHA");
     $return = @$this->real_connect($server != "" ? $host : ini_get("mysqli.default_host"), $server . $username != "" ? $username : ini_get("mysqli.default_user"), $server . $username . $password != "" ? $password : ini_get("mysqli.default_pw"), null, is_numeric($port) ? $port : ini_get("mysqli.default_port"), !is_numeric($port) ? $port : null, MYSQLI_CLIENT_SSL);
     return $return;
 }
Пример #19
0
 public function __construct()
 {
     mysqli_report(MYSQLI_REPORT_STRICT);
     try {
         $this->MySQLi = new mysqli($this->host, $this->username, $this->password, $this->database);
     } catch (Exception $e) {
         echo "Error Code: " . $e->getCode();
         echo "<br>Error Message: " . $e->getMessage();
     }
 }
Пример #20
0
 public function connect($host, $user, $password, $database)
 {
     mysqli_report(MYSQLI_REPORT_STRICT);
     try {
         $this->mysqli = new \mysqli($host, $user, $password, $database);
         //$this->query('SET NAMES utf8');
     } catch (\mysqli_sql_exception $e) {
         throw new Exception\ConnectionException('Mysql connection failed.');
     }
 }
Пример #21
0
 public function connect()
 {
     mysqli_report(MYSQLI_REPORT_STRICT);
     try {
         $this->conn = new mysqli($this->servername, $this->username, $this->password, $this->dbName);
     } catch (Exception $e) {
         echo json_encode(array('status' => 'error', 'message' => 'Connection Failed!' . "\r\n" . 'Server is unavailable'));
         die;
     }
     return $this->conn;
 }
Пример #22
0
 private function __construct()
 {
     $o = self::$options;
     // turn of error reporting
     mysqli_report(MYSQLI_REPORT_OFF);
     // connect to database
     @parent::__construct(isset($o['host']) ? $o['host'] : 'localhost', isset($o['user']) ? $o['user'] : '******', isset($o['pass']) ? $o['pass'] : '******', isset($o['dbname']) ? $o['dbname'] : 'weedo', isset($o['port']) ? $o['port'] : 3306, isset($o['sock']) ? $o['sock'] : false);
     // check if a connection established
     if (mysqli_connect_errno()) {
         throw new exception(mysqli_connect_error(), mysqli_connect_errno());
     }
 }
Пример #23
0
 public function __construct()
 {
     mb_internal_encoding('UTF-8');
     mb_regex_encoding('UTF-8');
     mysqli_report(MYSQLI_REPORT_STRICT);
     try {
         $this->link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
         $this->link->set_charset("utf8");
     } catch (Exception $e) {
         die('Unable to connect to database, goto http://github.com/amitkhare/slim-hmvc and read the docs about setting up database.');
     }
 }
Пример #24
0
 public function __construct($server, $dbname, $username, $password)
 {
     if (!class_exists('mysqli', false)) {
         throw new \Exception('MySQLi extension not available');
     }
     mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
     list($host, $port) = \Zeyon\extractServer($server, 3306);
     $this->db = new \mysqli($host, $username, $password, $dbname, $port);
     $this->db->set_charset('utf8');
     $this->db->real_query("SET sql_mode = 'ANSI_QUOTES,ERROR_FOR_DIVISION_BY_ZERO,IGNORE_SPACE,NO_BACKSLASH_ESCAPES,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,PIPES_AS_CONCAT,STRICT_TRANS_TABLES'");
     parent::__construct();
 }
Пример #25
0
 private function connect($hostname, $user, $password)
 {
     mysqli_report(MYSQLI_REPORT_STRICT);
     if (!class_exists('\\mysqli')) {
         throw new ModuleException('Mysqli class not found');
     }
     try {
         $this->mysqlHandler = new \mysqli($hostname, $user, $password);
     } catch (\mysqli_sql_exception $e) {
         throw new ModuleException('Can\'t Connect to Mysql');
     }
 }
Пример #26
0
 private function __construct()
 {
     mysqli_report(MYSQLI_REPORT_STRICT);
     try {
         $this->_connection = new mysqli($this->_host, $this->_username, $this->_password, $this->_database);
     } catch (mysqli_sql_exception $e) {
         throw new Exception($e->getMessage());
     }
     if (mysqli_connect_error()) {
         trigger_error("Failed to conencto to MySQL: " . mysql_connect_error(), E_USER_ERROR);
     }
 }
Пример #27
0
 public static function getMySqliConcrete()
 {
     try {
         // throw exceptions instead of PHP errors
         mysqli_report(MYSQLI_REPORT_STRICT);
         // connect!
         $mysqli = new mysqli("localhost", "root", "przmair", "przm");
         return $mysqli;
     } catch (mysqli_sql_exception $error) {
         throw new mysqli_sql_exception("Unable to connect to mySQL", 0, $error);
     }
 }
Пример #28
0
 public function __construct()
 {
     mb_internal_encoding('UTF-8');
     mb_regex_encoding('UTF-8');
     mysqli_report(MYSQLI_REPORT_STRICT);
     try {
         $this->link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
         $this->link->set_charset("utf8");
     } catch (Exception $e) {
         die('Unable to connect to database');
     }
 }
Пример #29
0
 /**
  * Returns a connection to the database.
  * 
  * @return mysqli connection to the database
  * @throws Exception if we can't connect to the database
  */
 public static function getConnection()
 {
     mysqli_report(MYSQLI_REPORT_STRICT);
     try {
         $conn = mysqli_init();
         $conn->real_connect(DatabaseConfig::HOST, DatabaseConfig::USER, DatabaseConfig::PASSWORD, DatabaseConfig::DATABASE, DatabaseConfig::PORT, NULL, MYSQLI_CLIENT_FOUND_ROWS);
         $conn->set_charset('utf8');
         return $conn;
     } catch (Exception $ex) {
         throw $ex;
     }
 }
Пример #30
0
 private function __construct()
 {
     mb_internal_encoding('UTF-8');
     mb_regex_encoding('UTF-8');
     mysqli_report(MYSQLI_REPORT_STRICT);
     $dsn = 'mysql:host=' . $this->host . '; dbname=' . $this->name . '; charset=utf8';
     $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
     try {
         $this->db = new PDO($dsn, $this->user, $this->pass, $options);
     } catch (PDOException $e) {
         exit('<p class="red"><strong>CONSTRUCT ERROR</strong></p>' . $e->getMessage());
     }
 }