* filename: db.php * charset: UTF-8 * create date: 2012-5-25 * * @author Zhao Binyan <*****@*****.**> * @copyright 2011-2012 Zhao Binyan * @link http://yungbo.com * @link http://weibo.com/itbudaoweng */ /** * 数据库初始化,如果直接调用此函数记得关闭。 * $db = db_init('default');//配置名称 * $db->query(); * $db->close(); */ set_conf('db_conf', $db_conf); function db_init($db_group = 'default') { IS_DB_ACTIVE or show_error('please check your database configration'); //数据库资源 $db = false; $db_username = ''; $db_passwd = ''; $db_database = ''; $db_host = 'localhost'; $db_port = '3306'; $db_conf = get_conf('db_conf'); $charset = str_replace('-', '', CHARSET); //将 utf-8 切换为 utf8 if (!$db_conf) { show_error('none valid database configration!');
$realfile = APP_NAME . 'static/' . $file; if (!file_exists($realfile)) { show_404('static file ' . $file . ' unexists'); } else { if (strtolower(substr($file, -3, 3)) == '.js') { return "<script src=\"{$realfile}\"></script>\r\n"; } else { if (strtolower(substr($file, -4, 4)) == '.css') { return "<link rel=\"stylesheet\" href=\"{$realfile}\" />\r\n"; } else { return $realfile; } } } } set_conf('autoload_config', $autoload_config); /** * 自动加载类 * @param unknown_type $class */ function __autoload($class) { $autoload_config = get_conf('autoload_config'); $flag = false; foreach ($autoload_config as $autoload) { $file = $autoload['path'] . strtolower($class) . $autoload['ext']; if (is_file($file)) { require $file; $flag = true; break; }
function wphp_custom_before_instance() { $timer = new Timer(); $timer->start(); set_conf('timer', $timer); }
error_reporting(0); show_error('bad SYS_MODE'); } //核心函数、控制器、模型 require CORE_NAME . 'func_inner.php'; require CORE_NAME . 'func.php'; require CORE_NAME . 'controller.php'; if (IS_DB_ACTIVE) { require CORE_NAME . 'db.php'; require CORE_NAME . 'model.php'; } $query_string = $_SERVER['QUERY_STRING']; //如需要做伪静态,除了服务器配置,也可以交给 wphp_custom_change_query_string 处理,可能用到 $_SERVER['PATH_INFO'] function_exists('wphp_custom_change_query_string') && ($query_string = wphp_custom_change_query_string($query_string)); set_conf('query_string', $query_string); set_conf('theme_package', $theme_package); // $c controller $c = get_param(PARAM_CONTROLLER) ? get_param(PARAM_CONTROLLER) : DEFAULT_CONTROLLER; // $a action $a = get_param(PARAM_ACTION) ? get_param(PARAM_ACTION) : DEFAULT_ACTION; //filter '..' $c = str_replace('..', '', $c); $a = str_replace('..', '', $a); //设置当前控制器和方法名 define('CUR_CONTROLLER', $c); define('CUR_ACTION', $a); function_exists('wphp_custom_before_instance') && wphp_custom_before_instance(); //加载控制器和方法 $file = APP_NAME . 'controller/' . strtolower($c) . '.php'; if (file_exists($file)) { require $file;