本文整理汇总了PHP中SQL::errno方法的典型用法代码示例。如果您正苦于以下问题:PHP SQL::errno方法的具体用法?PHP SQL::errno怎么用?PHP SQL::errno使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQL
的用法示例。
在下文中一共展示了SQL::errno方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
/**
* 执行SQL语句
*
* @param string $sql
* @return resource
*/
public static function query($sql)
{
$timestamp = microtime(true);
$r = mysqli_query(SQL::$connection, $sql);
$spent = round((microtime(true) - $timestamp) * 1000, 3);
if ($r) {
DEBUG::put('Query: ' . $sql . ' spent: ' . $spent . 'ms', 'MySQL');
} else {
DEBUG::put('Query: ' . $sql . ' fail: #' . SQL::errno() . ' ' . SQL::errmsg() . ' spent: ' . $spent, 'MySQL');
}
return $r;
}
示例2: while
$count = 0;
while ($tokens = fgetcsv($handle, 2048, $delimiter, $enclosure)) {
// insert one record at a time
$query = "INSERT INTO " . SQL::escape($_REQUEST['table_name']) . " (" . $headers . ") VALUES (";
// use all provided tokens
$index = 0;
foreach ($tokens as $token) {
if ($index++) {
$query .= ', ';
}
$query .= "'" . SQL::escape($token) . "'";
}
// finalize the statement
$query .= ')';
// execute the statement
if (!SQL::query($query, TRUE) && SQL::errno()) {
$context['text'] .= '<p>' . $here . ': ' . $query . BR . SQL::error() . "</p>\n";
}
$queries++;
// ensure we have enough time
if (!($queries % 50)) {
Safe::set_time_limit(30);
}
}
// clear the cache
Cache::clear();
// report of script data
$time = round(get_micro_time() - $context['start_time'], 2);
$context['text'] .= '<p>' . sprintf(i18n::s('%d SQL statements have been processed in %.2f seconds.'), $queries, $time) . '</p>';
// remember this in log as well
Logger::remember('tables/import.php: Data has been imported into ' . $_REQUEST['table_name'], $queries . ' SQL statements have been processed in ' . $time . ' seconds.');
示例3: query
/**
* query the database
*
* This function populates the error context, where applicable.
*
* @param string the SQL query
* @param boolean optional TRUE to not report on any error
* @param resource connection to be considered, if any
* @return the resource returned by the database server, or the number of affected rows, or FALSE on error
*/
public static function query(&$query, $silent = FALSE, $connection = NULL)
{
global $context;
// allow for reference
$output = FALSE;
// use the default connection
if (!$connection) {
// we do need a connection to the database
if (!isset($context['connection']) || !$context['connection']) {
return $output;
}
$connection = $context['connection'];
}
// reopen a connection if database is not reachable anymore
if (get_micro_time() - $context['start_time'] > 1.0 && !SQL::ping($connection)) {
// remember the error, if any -- we may not have a skin yet
if (!$silent) {
if (is_callable(array('Skin', 'error'))) {
Logger::error(i18n::s('Connection to the database has been lost'));
} else {
die(i18n::s('Connection to the database has been lost'));
}
}
// query cannot be processed
return $output;
}
// ensure enough execution time
Safe::set_time_limit(30);
// profile database requests
$query_stamp = get_micro_time();
// do the job
if (is_callable('mysqli_query')) {
$result = mysqli_query($connection, $query);
} else {
$result = mysql_query($query, $connection);
}
// finalize result
if ($result) {
// provide more than a boolean result
if ($result === TRUE) {
if (is_callable('mysqli_affected_rows')) {
$result = mysqli_affected_rows($connection);
} else {
$result = mysql_affected_rows($connection);
}
}
// flag slow requests
$duration = get_micro_time() - $query_stamp;
if ($duration >= 0.5 && $context['with_debug'] == 'Y') {
Logger::remember('shared/sql.php: SQL::query() slow request', $duration . "\n\n" . $query, 'debug');
}
// return the set of selected rows
return $result;
}
// remember the error, if any
if (SQL::errno($connection)) {
// display some error message
if (!$silent) {
if (is_callable(array('Skin', 'error'))) {
Logger::error($query . '<br />' . SQL::error($connection));
} else {
die($query . '<br />' . SQL::error($connection));
}
}
// log the error at development host
if ($context['with_debug'] == 'Y') {
Logger::remember('shared/sql.php: SQL::query()', SQL::error($connection) . "\n\n" . $query, 'debug');
}
}
// no valid result
return $output;
}
示例4: purge
/**
* delete all documentation pages
*/
public static function purge()
{
global $context;
// purge the old documentation
$query = "DELETE FROM " . SQL::table_name('phpdoc');
if (SQL::query($query, TRUE) === FALSE && SQL::errno()) {
echo $query . BR . SQL::error() . BR . "\n";
}
}