本文整理匯總了PHP中mysqli_report函數的典型用法代碼示例。如果您正苦於以下問題:PHP mysqli_report函數的具體用法?PHP mysqli_report怎麽用?PHP mysqli_report使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mysqli_report函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isInstalled
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: __construct
public function __construct($charset, $handler = null)
{
\mysqli_report(MYSQLI_REPORT_OFF);
$this->charset = $charset;
$this->connection = null;
$this->handler = $handler;
}
示例3: Init
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: initialise
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: query
/**
* Выполнение запроса к базе данных, выполняет коннект на запросе
*
* @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: __construct
/**
* 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'] : 'root';
$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: __construct
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: __construct
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: connect
/**
* 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: run
/**
* 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: __construct
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: __construct
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: connect
/**
* 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: __construct
/**
* 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: connect
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);
}
}