Ejemplo n.º 1
0
/**
 * 执行一条sql语句
 * @param string $sql
 * @param resource $db
 * @return bool
 */
function run_sql($sql, $db = NULL)
{
    is_null($db) && ($db = db());
    Logger::debug('run sql:' . $sql);
    $time = microtime(TRUE);
    $result = mysql_query($sql, $db);
    if (!isset($GLOBALS['run_sql'])) {
        $GLOBALS['run_sql'] = array();
    }
    $GLOBALS['run_sql'][$sql] = microtime(TRUE) - $time;
    $GLOBALS['last_sql'] = $sql;
    if (mysql_error()) {
        trigger_error('MySQL error ' . mysql_errno() . mysql_error() . "\n[{$sql}]", E_USER_ERROR);
    }
    // 触发执行 SQL 钩子
    run_func_coll('run_sql_after');
    return $result;
}
Ejemplo n.º 2
0
 * base controller
 */
abstract class _Control
{
    public function __construct()
    {
    }
}
// Controller预处理
$__cont_file = APP . $GLOBALS['request']['file'];
if (!is_file($__cont_file)) {
    trigger_error("Can\\'t find controller file: {$__cont_file}", E_USER_ERROR);
}
require $__cont_file;
$__class_name = $GLOBALS['request']['class'];
if (!class_exists($__class_name)) {
    trigger_error("Can\\'t find class: {$__class_name}", E_USER_ERROR);
}
$__bomb = new $__class_name();
$__method = $GLOBALS['request']['fn'];
if (!method_exists($__bomb, $__method)) {
    trigger_error("Can\\'t find method: {$__method}", E_USER_ERROR);
}
$__params = isset($GLOBALS['request']['params']) ? $GLOBALS['request']['params'] : array();
// 执行action 前置钩子
run_func_coll('pre_control');
// 执行action()方法
call_user_func_array(array($__bomb, $__method), $__params);
// 执行action 后置钩子
run_func_coll('post_control');
exit;