// 发送SQL语句函数
public function send_query( $sql )
{
switch ( strtoupper( $this->config->database ) )
{
case '
MYSQL' :
return $this->send_
mysql_query( $sql );
break;
case '
ACCESS' :
return $this->send_odbc_query( $sql );
break;
default :
$this->sys_err( '数据库类型错误,该类目前只支持
MYSQL与
ACCESS两种数据库', 'die' );
break;
}
}
// 发送SQL语句到
MYSQL函数
private function send_
mysql_query( $sql )
{
@$rs =
mysql_query( $sql, $this->conn );
if ( $rs == false )
{
$
mysql_err =
mysql_error();
$this->sys_err( "SQL语句:{{$sql}}执行失败,原因是:{{$
mysql_err}}", 'die' );
}
return $rs;
}
// 发送SQL语句到
ACCESS函数
private function send_odbc_query( $sql )
{
@$rs = odbc_exec( $this->conn, $sql );
if ( $rs == false )
{
$odbc_err = odbc_errormsg( $this->conn );
$this->sys_err( "SQL语句:{{$sql}}执行失败,原因是:{{$odbc_err}}", 'die' );
}
return $rs;
}
// 获取查询返回函数
public function select_query( $sql, $retuen_res = false )
{
$res = $this->send_query( $sql );
if ( $retuen_res == true )
{
return $res;
}
switch ( strtoupper( $this->config->database ) )
{
case '
MYSQL' :
return $this->select_
mysql_query( $res );
break;
case '
ACCESS' :
return $this->select_
access_query( $res );
break;
default :
$this->sys_err( '数据库类型错误,该类目前只支持
MYSQL与
ACCESS两种数据库', 'die');
break;
}
}
// 获取
MYSQL查询返回函数
private function select_
mysql_query( $res )
{
$arr = array();
while ( false != ( $rs =
mysql_fetch_assoc( $res ) ) )
{
$arr[] = $rs;
}
mysql_free_result( $res );
return ( count( $arr ) > 0 ? $arr : false );
}
// 获取ACCCESS查询返回函数
private function select_
access_query( $res )
{
$arr = array();
while ( false != ( $rs = odbc_fetch_array( $res ) ) )
{
$arr[] = $rs;
}
odbc_free_result( $res );
return ( count( $arr ) > 0 ? $arr : false );
}
// 获取系统错误函数
public function sys_err( $err_msg, $method, $err_notice = '很抱歉,本站发生系统错误,请稍候再试。' )
{
$this->err_record( 'sys', $err_msg );
switch ( $method )
{
case 'keep':
return;
break;
default:
$this->err_notice( $err_notice );
break;
}
}
// 获取用户错误函数
public function user_err( $err_notice, $method, $re_href = '', $err_msg = '' )
{
if ( !empty( $err_msg ) )
{
$this->err_record( 'user', $err_msg );
}
switch ( $method )
{
case 'keep':
return;
break;
default:
$this->err_notice( $err_notice, $re_href );
break;
}
}
// 记录错误函数
private function err_record( $type, $err_msg )
{
$err_url = $this->the_dir . 'lib/error/';
$err_url .= ( $type == 'sys' ? 'system.err' : 'user.err' );
$record_msg = date( 'Y-m-d H:i:s' ) . '|' . $err_msg . "\n";
$this->file_put( $err_url, $record_msg, 'ab' );
}
// 文件写入函数
public function file_put( $url, $content, $method )
{
$dir = str_replace( basename( $url ), '', $url );
if ( !file_exists( $dir ) )
{
$this->sys_err( "{{$dir}}文件夹不存在", 'die' );
}
@$f = fopen( $url, $method );
@flock( $f, LOCK_NM );
@fwrite( $f, $content, strlen( $content ) );
@flock( $f, LOCK_UN );
@fclose( $f );
}
// 提示错误函数
protected function err_notice( $err_notice, $re_href = '' )
{
$err_page = $this->the_dir . $this->err_page;
if ( !file_exists( $err_page ) )
{
$this->sys_err( '错误提示页面丢失', 'keep' );
die( '很抱歉,本站发生系统错误,请稍候再试。' );
}
$err_html = file_get_contents( $err_page );
$err_html = str_replace( '<%$err_notice%>', $err_notice, $err_html);
$err_html = str_replace( '<%$this_url%>', $this->the_dir, $err_html);
$err_html = str_replace( '<%$re_href%>', $re_href, $err_html);
echo $err_html;
exit;
}
// 用于设定模版文件路径的函数
function set_dir( $file_dir = 'smarty_file' )
{
if ( !preg_match( '{/$}', $file_dir ) )
{
$file_dir .= '/';
}
if ( !file_exists( $this->the_dir . $file_dir . $this->template_dir ) )
{
$this->sys_err( 'smarty模版路径丢失', 'die' );
}
if ( !file_exists( $this->the_dir . $file_dir . $this->compile_dir ) )
{
$this->sys_err( 'smarty编译路径丢失', 'die' );
}
if ( !file_exists( $this->the_dir . $file_dir . $this->cache_dir ) )
{
$this->sys_err( 'smarty缓存路径丢失', 'die' );
}
$this->template_dir = $this->the_dir . $file_dir . $this->template_dir;
$this->compile_dir = $this->the_dir . $file_dir . $this->compile_dir;
$this->cache_dir = $this->the_dir . $file_dir . $this->cache_dir;
}
// 生成静态页面函数
public function create_html( $tpl, $file_url = '', $html_name = '' )
{
$html_tpl = $this->fetch( $tpl );
//生成静态文件的文件名
if ( empty( $html_name ) )
{
$file_name = strtolower( basename( $_SERVER['PHP_SELF'] ) );
$file_name = str_replace( '.php', ".{$this->html_cache}", $file_name );
}
else
{
$file_name = $html_name;
}
if ( !empty( $file_url ) && !preg_match( '!\/$!', $file_url ) )
{
$file_url .= '/';
}
$file_url = !empty( $file_url ) ? $this->the_dir . $file_url : "./{$file_url}";
$file_url .= $file_name;
$this->file_put( $file_url, $html_tpl, 'wb');
header("location:{$file_url}");
exit();
}
// 转到静态页面
public function goto_html( $left_time = null, $file_url = '', $html_name = '' )
{
$left_time = ( $left_time == null ? $this->html_cache_lifetime : intval( $left_time ) );
//获取静态文件的文件名
if ( empty( $html_name ) )
{
$file_name = strtolower( basename( $_SERVER['PHP_SELF'] ) );
$file_name = str_replace( '.php', ".{$this->html_cache}", $file_name );
}
else
{
$file_name = $html_name;
}
if ( !empty( $file_url ) && !preg_match( '!\/$!', $file_url ) )
{
$file_url .= '/';
}
$file_url = !empty( $file_url ) ? $this->the_dir . $file_url : "./{$file_url}";
$file_url .= $file_name;
if ( !file_exists( $file_url) )
{
return;
}
if ( $left_time == -1 )
{
header("location:{$file_url}");
exit;
}
else
{
@$fmtime = filemtime( $file_url );
$fmtime = intval( $fmtime );
if ( time() - $fmtime <= $left_time )
{
header("location:{$file_url}");
exit;
}
}
}
}
?>
文章评论
共有 位脚本之家网友发表了评论我来说两句