discuz7 phpMysql操作类

前端之家收集整理的这篇文章主要介绍了discuz7 phpMysql操作类前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="81834" class="copybut" id="copybut81834" onclick="doCopy('code81834')"> 代码如下:

<div class="codebody" id="code81834"> @H_404_2@<?PHP @H_4042@/* @H404_2@ MysqL数据库连接类 @H_404_2@ MysqL.class.PHP 2009.04.15 by Hackbaby @H_4042@*/ @H4042@class dbstuff { @H4042@var $version = ''; @H4042@var $querynum = 0; @H4042@var $link = null; @H404_2@//连接数据库 @H_4042@function connect($dbhost,$dbuser,$dbpw,$dbname,$pconnect = 0,$halt = TRUE,$dbcharset2 = '') { @H404_2@$conn = empty($pconnect) ? 'MysqL_connect' : 'MysqLpconnect'; @H4042@if (!$this->link = @$conn($dbhost,1)) { @H404_2@$halt && $this->halt('Can not connect to MysqL server'); @H_4042@} else { @H4042@if($this->version() > '4.1') { @H4042@global $charset,$dbcharset; @H4042@$dbcharset = $dbcharset2 ? $dbcharset2 : $dbcharset; @H404_2@$dbcharset = !$dbcharset && in_array(strtolower($charset),array('gbk','big5','utf-8')) ? strreplace('-','',$charset) : $dbcharset; @H404_2@$serverset = $dbcharset ? 'character_set_connection='.$dbcharset.',character_set_results='.$dbcharset.',character_setclient=binary' : ''; @H404_2@$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',').'sqlmode=\'\'') : ''; @H404_2@$serverset && MysqLquery("SET $serverset",$this->link); @H4042@} @H404_2@$dbname && @MysqL_selectdb($dbname,$this->link); @H4042@} } @H404_2@//选择数据库 @H_404_2@function selectdb($dbname) { @H404_2@return MysqL_selectdb($dbname,$this->link); @H4042@} @H404_2@//数据库执行后的返回方法 @H_404_2@function fetch_array($query,$result_type = MysqLASSOC) { @H404_2@return MysqL_fetch_array($query,$resulttype); @H4042@} @H404_2@//返回fetch_array方法执行后的返回值 @H_404_2@function fetch_first($sql) { @H_404_2@return $this->fetch_array($this->query($sql)); @H_4042@} @H404_2@//返回result方法执行后的返回值 @H_404_2@function result_first($sql) { @H_404_2@return $this->result($this->query($sql),0); @H_4042@} @H404_2@//执行对数据库的操作 @H_404_2@function query($sql,$type = '') { @H_404_2@global $debug,$discuz_starttime,$sqldebug,$sqlspenttimes; @H_4042@//判断debug调试 @H404_2@if(defined('SYS_DEBUG') && SYSDEBUG) { @H404_2@@include_once WEB_ROOT.'./include/debug.func.PHP'; @H_404_2@sqldebug($sql); @H_4042@} @H4042@// @H404_2@$func = $type == 'UNBUFFERED' && @function_exists('MysqL_unbufferedquery') ? @H404_2@'MysqL_unbuffered_query' : 'MysqLquery'; @H404_2@if(!($query = $func($sql,$this->link))) { @H_404_2@if(inarray($this->errno(),array(2006,2013)) && substr($type,5) != 'RETRY') { @H4042@$this->close(); @H404_2@require './config.inc.PHP'; @H_4042@$this->connect($dbhost,$pconnect,true,$dbcharset); @H404_2@$this->query($sql,'RETRY'.$type); @H_4042@} elseif($type != 'SILENT' && substr($type,5) != 'SILENT') { @H404_2@$this->halt('MysqL Query Error',$sql); @H_4042@} @H4042@} @H404_2@//查询条数加1 @H_4042@$this->querynum++; @H4042@return $query; @H4042@} @H404_2@//取得前一次 MysqL 操作所影响的记录行数 @H_404_2@function affectedrows() { @H404_2@return MysqL_affectedrows($this->link); @H4042@} @H404_2@//数据库的文本错误提示 @H_4042@function error() { @H404_2@return (($this->link) ? MysqL_error($this->link) : MysqLerror()); @H4042@} @H404_2@//返回上一个 MysqL 操作中的错误信息的数字编码 @H_4042@function errno() { @H404_2@return intval(($this->link) ? MysqL_errno($this->link) : MysqLerrno()); @H4042@} @H404_2@//返回数据库操作结果 @H_4042@function result($query,$row = 0) { @H404_2@$query = @MysqLresult($query,$row); @H4042@return $query; @H4042@} @H404_2@//返回数据库查询等操作的数目 @H_404_2@function numrows($query) { @H404_2@$query = MysqL_numrows($query); @H4042@return $query; @H4042@} @H4042@//取得结果集中字段的数目 @H404_2@function numfields($query) { @H404_2@return MysqL_numfields($query); @H4042@} @H4042@//释放结果内存 @H404_2@function freeresult($query) { @H404_2@return MysqL_freeresult($query); @H4042@} @H4042@//取得上一步 INSERT 操作产生的 ID @H404_2@function insertid() { @H404_2@return ($id = MysqL_insert_id($this->link)) >= 0 ? $id : $this->result($this->query("SELECT last_insertid()"),0); @H4042@} @H404_2@//以数组的形式返回查询结果 @H_404_2@function fetchrow($query) { @H404_2@$query = MysqL_fetchrow($query); @H4042@return $query; @H4042@} @H4042@//从结果集中取得列信息并作为对象返回 @H404_2@function fetchfields($query) { @H404_2@return MysqL_fetchfield($query); @H4042@} @H404_2@//获取MysqL的版本 @H_4042@function version() { @H4042@if(empty($this->version)) { @H404_2@$this->version = MysqL_get_serverinfo($this->link); @H4042@} @H4042@return $this->version; @H4042@} @H404_2@//关闭连接 @H_4042@function close() { @H404_2@return MysqLclose($this->link); @H4042@} @H404_2@//错误提示 @H_404_2@function halt($message = '',$sql = '') { @H_404_2@define('CACHEFORBIDDEN',TRUE); @H404_2@require_once WEBROOT . './include/dbMysqL_error.inc.PHP'; @H_4042@} @H4042@} @H4042@?> @H404_2@

猜你在找的PHP相关文章