<?php
/* *
* 作者:joyphper
* 博客:www.joyphper.net
* QQ:97142822
* Copyright (C) 2011 - 2011 joyphper.net
* */
if (! defined ( 'App_PATH' ))exit ( 'request error' );
class mysql{
private $dbHost;
private $dbPort;
private $dbName;
private $dbUser;
private $dbPwd;
private $dbprefix;
private $language;
private $queryString;
private $linkID;
private $result;
public function __construct($conf)
{
$this->dbHost = $conf["Host"];
$this->dbPort = $conf["Port"];
$this->dbName = $conf["Database"];
$this->dbUser = $conf["User"];
$this->dbPwd = $conf["Pwd"];
$this->dbprefix = $conf["Prefix"];
$this->language = $conf["Language"];
$this->linkID = 0;
$this->result = array ();
$this->openMysql();
}
private function openMysql()
{
$this->linkID = @mysql_connect ( $this->dbHost.":".$this->dbPort, $this->dbUser, $this->dbPwd );
if (! $this->linkID)
{
appFun::ERROR ( '系统错误警告:连接数据库失败,可能数据库密码不对或数据库服务器出错!' );
}
$selectDb = @mysql_select_db ( $this->dbName );
if (! $selectDb) {
appFun::ERROR( '系统错误警告:选择数据库失败,请确认' . $this->dbName . '是否存在' );
}
@mysql_query ( "SET NAMES '" . $this->language . "', character_set_client=binary, sql_mode='', interactive_timeout=3600 ;", $this->linkID );
return true;
}
//设置SQL语句,会自动把SQL语句里的#_替换为$this->dbPrefix(在配置文件中为$cfg_dbprefix)
public function setQuery($queryStr)
{
$prefix = "#_";
$queryStr = str_replace ( $prefix, $this->dbprefix, $queryStr );
$this->queryString = $queryStr;
}
//执行一个带返回结果的SQL语句,如SELECT,SHOW等
public function execute($sql = '', $id = 'me')
{
if (! empty ( $sql ))
{
$this->setQuery ( $sql );
}
$this->result [$id] = mysql_query ( $this->queryString, $this->linkID );
if ($this->result [$id] === false)
{
appFun::ERROR ( '系统错误警告:' . $this->getError () . $sql . ' 执行错误' );
}
}
//boolean 执行一个不返回结果的SQL语句,如update,delete,insert等
public function execNoneQuery($queryStr = '')
{
if (! empty ( $queryStr ))
{
$this->setQuery ( $queryStr );
}
else
{
return false;
}
return mysql_query ( $this->queryString, $this->linkID );
}
//int 执行一个返回影响记录条数的SQL语句,如update,delete,insert等
public function execNoneQuery2($queryStr = '')
{
if (! empty ( $queryStr ))
{
$this->setQuery ( $queryStr );
}
@mysql_query ( $this->queryString, $this->linkID );
return mysql_affected_rows ( $this->linkID );
}
public function getArray($queryStr, $acctype = MYSQL_ASSOC)
{
$exeID=time();
$this->execute($queryStr,$exeID);
if ($this->result [$exeID] == 0)
{
return false;
}
else
{
while(false!=($row=$this->fetch($exeID)))
{
$rows[]=$row;
}
return $rows;
}
}
//返回当前的一条记录并把游标移向下一记录
// MYSQL_ASSOC、MYSQL_NUM、MYSQL_BOTH
public function fetch($id = 'me', $acctype = MYSQL_ASSOC)
{
if ($this->result [$id] == 0)
{
return false;
}
else
{
return mysql_fetch_array ( $this->result [$id], $acctype );
}
}
//以对象的方式返回一条记录游标移向下一条记录
function fetchObject($id = "me")
{
if ($this->result [$id] == 0) {
return false;
} else {
return mysql_fetch_object ( $this->result [$id] );
}
}
//执行一个SQL语句,返回前一条记录或仅返回一条记录
public function getOne($sql = '', $rtype="arr",$acctype = MYSQL_ASSOC)
{
if (! empty ( $sql ))
{
if (! eregi ( "limit", $sql ))
{
$this->setQuery ( eregi_replace ( "[,;]$", '', trim ( $sql ) ) . " limit 0,1;" );
}
else
{
$this->setQuery ( $sql );
}
}
$this->execute ( $this->queryString, 'one' );
if (!$this->result ["one"])
{
return false;
}
else
{
if($rtype=="arr")
{
$arr = $this->fetch( 'one', $acctype );
@mysql_free_result ( $this->result ["one"] );
return $arr;
}
elseif($rtype=="obj")
{
$obj= $this->fetchObject("one");
@mysql_free_result ( $this->result ["one"] );
return $obj;
}
else
{
appFun::ERROR ( '错误类型:' . $rtype );
}
}
}
//获取记录条数
public function getNumRows($id = 'me')
{
if ($this->result [$id] == 0)
{
return 0;
}
else
{
return mysql_num_rows ( $this->result [$id] );
}
}
//获取上一步INSERT操作产生的ID
public function getInsertId()
{
return @mysql_insert_id ( $this->linkID );
}
//释放记录集占用的资源
public function freeResult($id = "me")
{
@mysql_free_result ( $this->result [$id] );
}
//释放所有记录集占用的资源
public function freeResultAll()
{
if (! is_array ( $this->result ))
{
$this->freeResult ();
}
foreach ( $this->result as $vv ) {
if ($vv) {
@mysql_free_result ( $vv );
}
}
}
//事物回滚
public function transaction()
{
mysql_query("START TRANSACTION;", $this->linkID);
mysql_query("SET AUTOCOMMIT=0;", $this->linkID);
}
public function commit()
{
mysql_query("COMMIT;", $this->linkID);
}
public function rollback()
{
mysql_query("ROLLBACK;", $this->linkID);
}
//获取mysql执行错误
public function getError() {
return mysql_error () . ':' . mysql_errno ();
}
//关闭连接
public function closeMysql() {
return mysql_close ( $this->linkID );
}
}
?>
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1、用户发送请求 2、Web应该引入JHPHP框架文件 3、JH.php接收用户请求参数app,mod,act(默认)去选择不同的controlle文件的和方法 4、Controller选择并向model发送数据请求 5、Model接受请求,并向数据查询数据 6、Database返回查询结果给Model 7、Model接收数据并对数据进行格式化返回给Controller 8、Controller选择不同的view文件 9、View接受请求返回处理结果 10、Controller对Model和View返回的结果并对数据进行处理返回结JH.php文件 11、JH.php获取结果,返回给Web应用 12、Web应用获取处理结果返回给用户 详细请见: http://www.joyphper.net/article/201109/135.html http://www.joyphper.net/article/201109/136.html
资源推荐
资源详情
资源评论
收起资源包目录
JHPHP_V1.0.247.rar (27个子文件)
JH.php 2KB
views
home
main_index.php 205B
main_pageTest.php 167B
main_selectTest.php 46B
main_cacheTest.php 72B
models
phone.class.php 562B
HttpError
500.html 91B
images
co_01.gif 138B
404error.gif 2KB
co_02.gif 141B
bg04.gif 816B
co_03.gif 141B
co_04.gif 142B
bg03.gif 52B
bg01.gif 52B
bg02.gif 52B
404.html 3KB
controllers
home
main.class.php 719B
Inc
appFun.php 3KB
appConfig.php 2KB
gustbook.sql 46KB
index.php 61B
cache
482e6bf126ddfa130b3395e09ed14c5a 332B
Core
class
cache.class.php 2KB
mysql.class.php 5KB
appModel.php 5KB
appController.php 1KB
共 27 条
- 1
资源评论
- itscat2015-07-06非常谢谢,具有很大的参考价值。
stjdydayou
- 粉丝: 2
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功