1.给测测,提提意见.
2.给评评,有什么问题没有,需要改进什么地方,就算是自我考试给打个分数,就10分制吧,10分是满分哦!
3.请留邮件.
84 个解决方案
#1
no text
#2
请留邮件!
#3
我来看看,谢了!kinderhuang@hotmail.com
#4
3Q: mydll@163.com
#5
关注 haidazhang@163.com
#6
zyj@wmdf.cn
#7
tfhxg@163.com
#8
大家有什么建议没有啊?
#9
大家别忘了给测评,打分!
#10
晕 没收到谈何建议
#11
刚刚重发了,请查收!
#12
<?php
////简单实例:
require("class/mydbsClass.php");
session_start();
$acs = new mydb("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs.mdb"));
$acs->debug = true;
//1.1.select+fetch_row
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
echo "</table>";
//1.2.select+fetch_array
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//2.插入/更新/删除/...
$acs->execute("insert into tmp01(name) values('姓名')");
//3.分页
$rs = $acs->SelectLimit("select * from tmp01 order by id",2,10);
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//4.session
$acs->CreateLoginInfoTable();//创建,只能做一次
$acs->FlashSessionLoginInfo();//刷新
echo "<br>:".$acs->setSessionLoginInfo(用户ID,session_id(),IP地址,date("Y-m-d H:i"),date("U")); //设置
?>
////简单实例:
require("class/mydbsClass.php");
session_start();
$acs = new mydb("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs.mdb"));
$acs->debug = true;
//1.1.select+fetch_row
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
echo "</table>";
//1.2.select+fetch_array
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//2.插入/更新/删除/...
$acs->execute("insert into tmp01(name) values('姓名')");
//3.分页
$rs = $acs->SelectLimit("select * from tmp01 order by id",2,10);
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//4.session
$acs->CreateLoginInfoTable();//创建,只能做一次
$acs->FlashSessionLoginInfo();//刷新
echo "<br>:".$acs->setSessionLoginInfo(用户ID,session_id(),IP地址,date("Y-m-d H:i"),date("U")); //设置
?>
#13
各位收到没有? 有问题请回复!
#14
根据实例谈点感受
$acs = new mydb("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs.mdb"));
$acs->debug = true;
*** 最好能简化成
$acs = new mydb("access:dbname=dbs.mdb", $username, $password);
//1.1.select+fetch_row
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
echo "</table>";
*** open方法易产生歧异,宜改为query或select
//1.2.select+fetch_array
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//2.插入/更新/删除/...
$acs->execute("insert into tmp01(name) values('姓名')");
*** execute方法就一定不执行select指令吗?
//3.分页
$rs = $acs->SelectLimit("select * from tmp01 order by id",2,10);
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
*** 没有all方法吗?你都需要一条一条记录处理吗?
//4.session
$acs->CreateLoginInfoTable();//创建,只能做一次
$acs->FlashSessionLoginInfo();//刷新
echo "<br>:".$acs->setSessionLoginInfo(用户ID,session_id(),IP地址,date("Y-m-d H:i"),date("U")); //设置
*** CreateLoginInfoTable宜自动完成
$acs = new mydb("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs.mdb"));
$acs->debug = true;
*** 最好能简化成
$acs = new mydb("access:dbname=dbs.mdb", $username, $password);
//1.1.select+fetch_row
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
echo "</table>";
*** open方法易产生歧异,宜改为query或select
//1.2.select+fetch_array
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//2.插入/更新/删除/...
$acs->execute("insert into tmp01(name) values('姓名')");
*** execute方法就一定不执行select指令吗?
//3.分页
$rs = $acs->SelectLimit("select * from tmp01 order by id",2,10);
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
*** 没有all方法吗?你都需要一条一条记录处理吗?
//4.session
$acs->CreateLoginInfoTable();//创建,只能做一次
$acs->FlashSessionLoginInfo();//刷新
echo "<br>:".$acs->setSessionLoginInfo(用户ID,session_id(),IP地址,date("Y-m-d H:i"),date("U")); //设置
*** CreateLoginInfoTable宜自动完成
#15
lch-1983@163.com
瞧一瞧,看一看
瞧一瞧,看一看
#16
xuzuning(唠叨) 的意见不错,不过我有以下问题:
*** 没有all方法吗?你都需要一条一条记录处理吗?
是什么意思?能不能说详细些,我还不大明白.
*** CreateLoginInfoTable宜自动完成
我这样考虑的,如果自动创建的话,则每次都要加判断,会影响速度!
*** 没有all方法吗?你都需要一条一条记录处理吗?
是什么意思?能不能说详细些,我还不大明白.
*** CreateLoginInfoTable宜自动完成
我这样考虑的,如果自动创建的话,则每次都要加判断,会影响速度!
#17
qinkui7@126.com
看看
看看
#18
alfredzeng@gmail.com
学习
学习
#19
大家别忘了给测评,打分!
#20
*** 没有all方法吗?你都需要一条一条记录处理吗?
是什么意思?能不能说详细些,我还不大明白.
一次读取全部查询结果到数组
是什么意思?能不能说详细些,我还不大明白.
一次读取全部查询结果到数组
#21
明白了,待我改进一下.
#22
请问:xuzuning(唠叨)
*** CreateLoginInfoTable宜自动完成
应该怎么做呢?
*** CreateLoginInfoTable宜自动完成
应该怎么做呢?
#23
zhizhi@265.com 观摩一下哈
#24
*** CreateLoginInfoTable宜自动完成
应该怎么做呢?
其实,当不是自动完成的时候,你并不能保证在session表建立以后就不会有
$asc->CreateLoginInfoTable();
出现
于是你依然是要在CreateLoginInfoTable方法中判断session表是否已被建立
所以可在类初始化的时候执行CreateLoginInfoTable
应该怎么做呢?
其实,当不是自动完成的时候,你并不能保证在session表建立以后就不会有
$asc->CreateLoginInfoTable();
出现
于是你依然是要在CreateLoginInfoTable方法中判断session表是否已被建立
所以可在类初始化的时候执行CreateLoginInfoTable
#25
初始化时如果要建立表的话,那么就会出现有可能表已经存在的问题.
那应该如何来判断呢?
那应该如何来判断呢?
#26
检查数据库中是否存在某个表,对于不同的数据库有不同的指令。
你可以参考adodb的MetaDatabases方法中的代码
简单的写法是利用错误处理机制,设表名为tbl_name
if(! @xxx_query('select * from tbl_name where 1=0'))
//表不存在的处理代码
当表不存在的时候 select * from tbl_name where 1=0 将会出错并返回假
由于@屏蔽了错误信息,所以错误信息是不会显示的
你可以参考adodb的MetaDatabases方法中的代码
简单的写法是利用错误处理机制,设表名为tbl_name
if(! @xxx_query('select * from tbl_name where 1=0'))
//表不存在的处理代码
当表不存在的时候 select * from tbl_name where 1=0 将会出错并返回假
由于@屏蔽了错误信息,所以错误信息是不会显示的
#27
十分感谢 xuzuning(唠叨)
我有不断完善这个类的.
我有不断完善这个类的.
#28
function MetaDatabases()
{
global $ADODB_FETCH_MODE;
if ($this->metaDatabasesSQL) {
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
$arr = $this->GetCol($this->metaDatabasesSQL);
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
return $arr;
}
return false;
}
ADODB中的这段代码我有些地方看不懂.
SetFetchMode($savem); 是什么意思?
{
global $ADODB_FETCH_MODE;
if ($this->metaDatabasesSQL) {
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
$arr = $this->GetCol($this->metaDatabasesSQL);
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
return $arr;
}
return false;
}
ADODB中的这段代码我有些地方看不懂.
SetFetchMode($savem); 是什么意思?
#29
fanglibang@163.com
#30
zalvsa@163.com
#31
根据fetch mode来实现取的时候是以数字做索引还是字段名做索引
mysql有两种 MYSQL_NUM, MYSQL_ASSOC
你看看mysql_fetch_array函数的定义就知道了
mysql有两种 MYSQL_NUM, MYSQL_ASSOC
你看看mysql_fetch_array函数的定义就知道了
#32
这个类中两种都支持
以数字为索引:
while($r = $acs->fetch_now($rs)){
echo $r[0].$r[1];
}
以字段做索引:
while($r = $acs->fetch_array($rs)){
echo $r["id"].$r["name"];
}
以数字为索引:
while($r = $acs->fetch_now($rs)){
echo $r[0].$r[1];
}
以字段做索引:
while($r = $acs->fetch_array($rs)){
echo $r["id"].$r["name"];
}
#33
fj_1@126.com
#34
fj_1@tom.com.误写..呵呵.
#35
jdhsd@sohu.com
#36
现在把类代码贴出来吧:
第一部分:
<?php
/*
请您保留以下信息.
数据库操作公共类 V2.0 beta 2.0.5 版
版本所有:张洋软件工作室(C)
TEL: 130????7627
QQ: 47488357
E-Mail:117zy@sohu.com
2005.10
可操作数据库: access,mysql,mssql
版本说明:
1.2005.10.13,V1.0版:
v1.0版,可以执行access,MYSQL,MSSQL三个版本.
可以执行SQL语句.
2.2005.10.15 V2.0 beta 2.0.1版:
在1.0版基础,新增了更多参数设置功能.
3.2005.10.16 V2.0 beta 2.0.2版:
在beta 2.0.1版基础上,改进了fetch_row()和fetch_array(),使各种数据库统一使用一种回显.
4.2005.10.18 V2.0 beta 2.0.3版:
在beta 2.0.2版基础上,增加了SelectLimit函数,实现了简单的分页程序.
增加了$this->debug显示调试.
5.2005.10.21 V2.0 beta 2.0.4版
在beta 2.0.3版基础上,增加了InsertAdd函数,实现了较复杂的插入.
6.2005.10.23 V2.0 beta 2.0.5版
在beta 2.0.4版基础上,增加了Session在查登录功能.
*/
class mydb{
var $dbClass; //数据库类型.access:mysql:mssql;
var $conn; //连接
var $dbName; //数据库名称
var $sqlstr; //SQL语句
var $info; //信息
var $args = array();
var $rowcount; //结果集指针
var $dataSet = array(); //数据结果集
var $bof; //开始标志
var $eof; //结束标志
var $accessFetch; //结果集读取标志
var $runtime; //测试运行时间
var $debug; //测试设置,默认值:false
// 翻页参数设置
var $CurrentPage; //当前页号
var $MaxPage; //最大页号
var $Linage; //每页行数
var $PaginalFormat; //翻页样式
var $MaxCount; //记录总数(指查询返回数)
var $offset; //偏移量,指记录的开始
//
var $sql1; //
var $sql2; //
//session设置
var $SessionTime; //$Session保存时间,分
//1.设置 ========================================================
//1.1.构造
function mydbs($_dbClass="access"){
$this->dbClass = $_dbClass;
$this->rowcount = 0;
$this->eof = false;
$this->bof = false;
$this->accessFetch = true;
$this->debug = false;
//设置分页参数
$this->CurrentPage = 1;
$this->MaxPage = 1;
$this->MaxCount = 1;
$this->Linage = 0;
//设置session
$this->SessionTime = 5;
}//end.mydbs;
//1.2.设置数据库类型
function setDbClass(&$_dbClass){
$this->dbClass = $_dbClass;
}//end.setDbClass;
//0.0.释放 ------------------------------------------------------
function db_close($_args = array()){
switch($this->dbClass){
case "access":
break;
case "mysql":
if(isset($_args[0])) return @mysql_close($_args[0]);
else return @mysql_close();
break;
case "mssql":
if(isset($_args[0])) return @mssql_close($_args[0]);
else return @mssql_close();
break;
}//end.switch;
}//end.db_close;
第一部分:
<?php
/*
请您保留以下信息.
数据库操作公共类 V2.0 beta 2.0.5 版
版本所有:张洋软件工作室(C)
TEL: 130????7627
QQ: 47488357
E-Mail:117zy@sohu.com
2005.10
可操作数据库: access,mysql,mssql
版本说明:
1.2005.10.13,V1.0版:
v1.0版,可以执行access,MYSQL,MSSQL三个版本.
可以执行SQL语句.
2.2005.10.15 V2.0 beta 2.0.1版:
在1.0版基础,新增了更多参数设置功能.
3.2005.10.16 V2.0 beta 2.0.2版:
在beta 2.0.1版基础上,改进了fetch_row()和fetch_array(),使各种数据库统一使用一种回显.
4.2005.10.18 V2.0 beta 2.0.3版:
在beta 2.0.2版基础上,增加了SelectLimit函数,实现了简单的分页程序.
增加了$this->debug显示调试.
5.2005.10.21 V2.0 beta 2.0.4版
在beta 2.0.3版基础上,增加了InsertAdd函数,实现了较复杂的插入.
6.2005.10.23 V2.0 beta 2.0.5版
在beta 2.0.4版基础上,增加了Session在查登录功能.
*/
class mydb{
var $dbClass; //数据库类型.access:mysql:mssql;
var $conn; //连接
var $dbName; //数据库名称
var $sqlstr; //SQL语句
var $info; //信息
var $args = array();
var $rowcount; //结果集指针
var $dataSet = array(); //数据结果集
var $bof; //开始标志
var $eof; //结束标志
var $accessFetch; //结果集读取标志
var $runtime; //测试运行时间
var $debug; //测试设置,默认值:false
// 翻页参数设置
var $CurrentPage; //当前页号
var $MaxPage; //最大页号
var $Linage; //每页行数
var $PaginalFormat; //翻页样式
var $MaxCount; //记录总数(指查询返回数)
var $offset; //偏移量,指记录的开始
//
var $sql1; //
var $sql2; //
//session设置
var $SessionTime; //$Session保存时间,分
//1.设置 ========================================================
//1.1.构造
function mydbs($_dbClass="access"){
$this->dbClass = $_dbClass;
$this->rowcount = 0;
$this->eof = false;
$this->bof = false;
$this->accessFetch = true;
$this->debug = false;
//设置分页参数
$this->CurrentPage = 1;
$this->MaxPage = 1;
$this->MaxCount = 1;
$this->Linage = 0;
//设置session
$this->SessionTime = 5;
}//end.mydbs;
//1.2.设置数据库类型
function setDbClass(&$_dbClass){
$this->dbClass = $_dbClass;
}//end.setDbClass;
//0.0.释放 ------------------------------------------------------
function db_close($_args = array()){
switch($this->dbClass){
case "access":
break;
case "mysql":
if(isset($_args[0])) return @mysql_close($_args[0]);
else return @mysql_close();
break;
case "mssql":
if(isset($_args[0])) return @mssql_close($_args[0]);
else return @mssql_close();
break;
}//end.switch;
}//end.db_close;
#37
//2.连接 ========================================================
//2.0.连接
/*
调用方法:
1.Access:
格式: db_connect(array([string server_name[,int codepage]]));
server_name: DCOM 服务器的名字,组件在此服务器上被取用。如果是 NULL,则假定是 localhost。想要允许 DCOM,必须将 php.ini 中的 com.allow_dcom 设为 TRUE。
codepage: 指定用于将 PHP 字符串(php-strings)转换成 UNICODE 字符串(unicode-strings)的代码页,反之亦然。可用的值为 CP_ACP、CP_MACCP、CP_OEMCP、CP_SYMBOL、CP_THREAD_ACP, CP_UTF7 和 CP_UTF8。
-----------------------------------------------------------------
2.MySQL:
格式: db_connect(array([string server [, string username [, string password [, bool new_link [, int client_flags]]]]]));
建立一个到 MySQL 服务器的连接。当没有提供可选参数时使用以下默认值:server = 'localhost:3306',username = 服务器进程所有者的用户名,password = 空密码。
server 参数可以包括端口号。例如 "hostname:port" 或者是到本地套接字的路径,例如本机上的 ":/path/to/socket"。
注: 无论指定 "localhost" 或者 "localhost:port" 作为 server,MySQL 客户端库将覆盖之并尝试连接到本地套接字(Windows 中的名字管道)。如果希望使用 TCP/IP 连接,用 "127.0.0.1" 替代 "localhost"。如果 MySQL 客户端库试图连接到错误的本地套接字,则应该在 PHP 配置中将 mysql.default_host 设为正确的路径并使 server 字段为空。
":port" 的支持是 PHP 3.0B4 起加入的。
":/path/to/socket" 的支持是 PHP 3.0.10 起加入的。
-----------------------------------------------------------------
3.MS SQL:
格式: db_connect(array([string servername [, string username [, string password]]]));
servername : 服务器名.
username: 用户名.
password: 密码.
-----------------------------------------------------------------
*/
function db_connect($_args = array()){
$this->args = $_args;
switch($this->dbClass){
case "access":
$this->access_db_connect();
return $this->conn;
break;
case "mysql":
$this->mysql_db_connect();
return $this->conn;
break;
case "mssql":
$this->mssql_db_connect();
return $this->conn;
break;
default:
return false;
break;
}//end.switch;
}//end.db_connect;
//2.1.连接Access
function access_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @new COM("ADODB.Connection");
break;
case 1:
$this->conn = @new COM("ADODB.Connection",$this->args[0]);
break;
case 2:
$this->conn = @new COM("ADODB.Connection",$this->args[0],$this->args[1]);
break;
default:
$this->conn = false;
break;
}//end.switch;
}//end.access_db_connect;
//2.2.1.连接MySQL
function mysql_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @mysql_connect();
break;
case 1:
$this->conn = @mysql_connect($this->args[0]);
break;
case 2:
$this->conn = @mysql_connect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2]);
break;
case 4:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2],$this->args[3]);
break;
case 5:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2],$this->args[3],$this->args[4]);
break;
default:
return false;
break;
}
}//end.mysql_db_connect;
//2.2.2.连接MySQL
function mysql_db_pconnect(){
switch(count($this->args)){
case 0:
$this->conn = @mysql_pconnect();
break;
case 1:
$this->conn = @mysql_pconnect($this->args[0]);
break;
case 2:
$this->conn = @mysql_pconnect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mysql_pconnect($this->args[0],$this->args[1],$this->args[2]);
break;
default:
$this->conn = false;
break;
}
}//end.mysql_db_connect;
//2.3.连接MS SQL
function mssql_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @mssql_connect();
break;
case 1:
$this->conn = @mssql_connect($this->args[0]);
break;
case 2:
$this->conn = @mssql_connect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mssql_connect($this->args[0],$this->args[1],$this->args[2]);
break;
default:
$this->conn = false;
break;
}
}//end.mssql_db_connect;
//3.选择数据库 ==================================================
//3.1.选择数据库
/*
调用方法:
1.access:
格式: select_db(array(string dbName [, string UserID [, string Password]]))
dbName : 数据库名(相对路径+数据库名)
UserID : 用户ID
Password : 密码
-----------------------------------------------------------------
2.MySQL:
格式: select_db(array(string database_name [, resource link_identifier]))
database_name : 数据库名
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: select_db(array(string database_name [, resource link_identifier]))
database_name : 数据库名
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function select_db($_args = array()){
$this->args = $_args;
switch($this->dbClass){
case "access":
$this->db_access_select_db();
return $this->conn;
break;
case "mysql":
return $this->db_mysql_select_db();
break;
case "mssql":
return $this->db_mssql_select_db();
break;
default:
break;
}//end.switch;
}//end.select_db;
//3.2.access选择数据库
function db_access_select_db(){
switch(count($this->args)){
case 1:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";";
$this->conn->open($dsn);
break;
case 2:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";UID=".$this->args[1].";";
$this->conn->open($dsn);
break;
case 3:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";UID=".$this->args[1].";Pwd=".$this->args[2].";";
$this->conn->open($dsn);
break;
default:
return false;
break;
}//end.switch;
}//end.
//3.3.MySQL选择数据库
function db_mysql_select_db(){
if(isset($this->args[1])) return @mysql_select_db($this->args[0],$this->args[1]);
else return @mysql_select_db($this->args[0]);
}//end.db_mysql_select_db;
//3.4.MsSQL选择数据库
function db_mssql_select_db($_args = array()){
if(isset($this->args[1])) return @mssql_select_db($this->args[0],$this->args[1]);
else return @mssql_select_db($this->args[0]);
}//end.db_mysql_select_db;
//2.0.连接
/*
调用方法:
1.Access:
格式: db_connect(array([string server_name[,int codepage]]));
server_name: DCOM 服务器的名字,组件在此服务器上被取用。如果是 NULL,则假定是 localhost。想要允许 DCOM,必须将 php.ini 中的 com.allow_dcom 设为 TRUE。
codepage: 指定用于将 PHP 字符串(php-strings)转换成 UNICODE 字符串(unicode-strings)的代码页,反之亦然。可用的值为 CP_ACP、CP_MACCP、CP_OEMCP、CP_SYMBOL、CP_THREAD_ACP, CP_UTF7 和 CP_UTF8。
-----------------------------------------------------------------
2.MySQL:
格式: db_connect(array([string server [, string username [, string password [, bool new_link [, int client_flags]]]]]));
建立一个到 MySQL 服务器的连接。当没有提供可选参数时使用以下默认值:server = 'localhost:3306',username = 服务器进程所有者的用户名,password = 空密码。
server 参数可以包括端口号。例如 "hostname:port" 或者是到本地套接字的路径,例如本机上的 ":/path/to/socket"。
注: 无论指定 "localhost" 或者 "localhost:port" 作为 server,MySQL 客户端库将覆盖之并尝试连接到本地套接字(Windows 中的名字管道)。如果希望使用 TCP/IP 连接,用 "127.0.0.1" 替代 "localhost"。如果 MySQL 客户端库试图连接到错误的本地套接字,则应该在 PHP 配置中将 mysql.default_host 设为正确的路径并使 server 字段为空。
":port" 的支持是 PHP 3.0B4 起加入的。
":/path/to/socket" 的支持是 PHP 3.0.10 起加入的。
-----------------------------------------------------------------
3.MS SQL:
格式: db_connect(array([string servername [, string username [, string password]]]));
servername : 服务器名.
username: 用户名.
password: 密码.
-----------------------------------------------------------------
*/
function db_connect($_args = array()){
$this->args = $_args;
switch($this->dbClass){
case "access":
$this->access_db_connect();
return $this->conn;
break;
case "mysql":
$this->mysql_db_connect();
return $this->conn;
break;
case "mssql":
$this->mssql_db_connect();
return $this->conn;
break;
default:
return false;
break;
}//end.switch;
}//end.db_connect;
//2.1.连接Access
function access_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @new COM("ADODB.Connection");
break;
case 1:
$this->conn = @new COM("ADODB.Connection",$this->args[0]);
break;
case 2:
$this->conn = @new COM("ADODB.Connection",$this->args[0],$this->args[1]);
break;
default:
$this->conn = false;
break;
}//end.switch;
}//end.access_db_connect;
//2.2.1.连接MySQL
function mysql_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @mysql_connect();
break;
case 1:
$this->conn = @mysql_connect($this->args[0]);
break;
case 2:
$this->conn = @mysql_connect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2]);
break;
case 4:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2],$this->args[3]);
break;
case 5:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2],$this->args[3],$this->args[4]);
break;
default:
return false;
break;
}
}//end.mysql_db_connect;
//2.2.2.连接MySQL
function mysql_db_pconnect(){
switch(count($this->args)){
case 0:
$this->conn = @mysql_pconnect();
break;
case 1:
$this->conn = @mysql_pconnect($this->args[0]);
break;
case 2:
$this->conn = @mysql_pconnect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mysql_pconnect($this->args[0],$this->args[1],$this->args[2]);
break;
default:
$this->conn = false;
break;
}
}//end.mysql_db_connect;
//2.3.连接MS SQL
function mssql_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @mssql_connect();
break;
case 1:
$this->conn = @mssql_connect($this->args[0]);
break;
case 2:
$this->conn = @mssql_connect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mssql_connect($this->args[0],$this->args[1],$this->args[2]);
break;
default:
$this->conn = false;
break;
}
}//end.mssql_db_connect;
//3.选择数据库 ==================================================
//3.1.选择数据库
/*
调用方法:
1.access:
格式: select_db(array(string dbName [, string UserID [, string Password]]))
dbName : 数据库名(相对路径+数据库名)
UserID : 用户ID
Password : 密码
-----------------------------------------------------------------
2.MySQL:
格式: select_db(array(string database_name [, resource link_identifier]))
database_name : 数据库名
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: select_db(array(string database_name [, resource link_identifier]))
database_name : 数据库名
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function select_db($_args = array()){
$this->args = $_args;
switch($this->dbClass){
case "access":
$this->db_access_select_db();
return $this->conn;
break;
case "mysql":
return $this->db_mysql_select_db();
break;
case "mssql":
return $this->db_mssql_select_db();
break;
default:
break;
}//end.switch;
}//end.select_db;
//3.2.access选择数据库
function db_access_select_db(){
switch(count($this->args)){
case 1:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";";
$this->conn->open($dsn);
break;
case 2:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";UID=".$this->args[1].";";
$this->conn->open($dsn);
break;
case 3:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";UID=".$this->args[1].";Pwd=".$this->args[2].";";
$this->conn->open($dsn);
break;
default:
return false;
break;
}//end.switch;
}//end.
//3.3.MySQL选择数据库
function db_mysql_select_db(){
if(isset($this->args[1])) return @mysql_select_db($this->args[0],$this->args[1]);
else return @mysql_select_db($this->args[0]);
}//end.db_mysql_select_db;
//3.4.MsSQL选择数据库
function db_mssql_select_db($_args = array()){
if(isset($this->args[1])) return @mssql_select_db($this->args[0],$this->args[1]);
else return @mssql_select_db($this->args[0]);
}//end.db_mysql_select_db;
#38
//4.执行SQL语句 =================================================
//4.1.执行返回结果集的SQL语句
/*
调用方法:
1.access:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
2.MySQL:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function open($_sqlstr,$_conn = null){
$this->sqlstr = $_sqlstr;
if($this->debug) echo "<br>SQL: " . $_sqlstr;
$this->bof = true;
$this->eof = false;
$this->accessFetch = true;
switch($this->dbClass){
case "access":
return $this->open_access($_sqlstr);
break;
case "mysql":
return $this->open_mysql($_sqlstr,$_conn);
break;
case "mssql":
return $this->open_mssql($_sqlstr,$_conn);
break;
default:
$this->eof = true;
return false;
break;
}//end.switch;
}//end.open;
//4.1.1.access.执行返回结果集的SQL语句
function open_access($_sqlstr){
//echo "SQL:" . $_sqlstr . "<br>";
return $this->conn->Execute($_sqlstr);
}//end.open_access;
//4.1.2.MySQL.执行返回结果集的SQL语句
function open_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
return @mysql_query($_sqlstr,$_conn);
else
return @mysql_query($_sqlstr);
}//end.open_mysql;
//4.1.3.MS SQL.执行返回结果集的SQL语句
function open_mssql(&$_sqlstr,&$_conn){
if(isset($_conn))
return @mysql_query($_sqlstr,$_conn);
else
return @mysql_query($_sqlstr);
}//end.open_mssql;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//4.2.执行不返回结果集的SQL语句
/*
调用方法:
1.access:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
2.MySQL:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function execute($_sqlstr,$_conn = null){
$this->sqlstr = $_sqlstr;
if($this->debug) echo "<br>SQL: " . $_sqlstr;
$this->bof = false;
$this->eof = false;
switch($this->dbClass){
case "access":
$this->exec_access($_sqlstr);
break;
case "mysql":
$this->exec_mysql($_sqlstr,$_conn);
break;
//case "mysql_db":
// $this->exec_db_mysql($_sqlstr,$_conn);
case "mssql":
$this->exec_mssql($_sqlstr,$_conn);
break;
default:
break;
}//end.switch;
}//end.execute;
//4.2.1.access.执行不返回结果集的SQL语句
function exec_access(&$_sqlstr){
$this->conn->Execute($_sqlstr);
}//end.exec_access;
//4.2.2.1.MySQL.执行不返回结果集的SQL语句
function exec_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
@mysql_query($_sqlstr,$_conn);
else
@mysql_query($_sqlstr);
}//end.exec_mysql;
//4.2.2.2.MySQL.执行不返回结果集的SQL语句
/*
function exec_db_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
$info = @mysql_query($this->args[0],$this->args[1],$this->args[2]);
else
$info = @mysql_query($this->args[0],$this->args[1]);
}//end.exec_mysql;
*/
//4.2.3.MS SQL.执行不返回结果集的SQL语句
function exec_mssql(&$_sqlstr,&$_conn){
if(isset($_conn))
@mysql_query($_sqlstr,$_conn);
else
@mysql_query($_sqlstr);
}//end.exec_mssql;
//4.3.执行不返回结果集的SQL语句(简写)
function exec($_args = array()){
$this->execute($_args);
}//end.exec;
//4.1.执行返回结果集的SQL语句
/*
调用方法:
1.access:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
2.MySQL:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function open($_sqlstr,$_conn = null){
$this->sqlstr = $_sqlstr;
if($this->debug) echo "<br>SQL: " . $_sqlstr;
$this->bof = true;
$this->eof = false;
$this->accessFetch = true;
switch($this->dbClass){
case "access":
return $this->open_access($_sqlstr);
break;
case "mysql":
return $this->open_mysql($_sqlstr,$_conn);
break;
case "mssql":
return $this->open_mssql($_sqlstr,$_conn);
break;
default:
$this->eof = true;
return false;
break;
}//end.switch;
}//end.open;
//4.1.1.access.执行返回结果集的SQL语句
function open_access($_sqlstr){
//echo "SQL:" . $_sqlstr . "<br>";
return $this->conn->Execute($_sqlstr);
}//end.open_access;
//4.1.2.MySQL.执行返回结果集的SQL语句
function open_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
return @mysql_query($_sqlstr,$_conn);
else
return @mysql_query($_sqlstr);
}//end.open_mysql;
//4.1.3.MS SQL.执行返回结果集的SQL语句
function open_mssql(&$_sqlstr,&$_conn){
if(isset($_conn))
return @mysql_query($_sqlstr,$_conn);
else
return @mysql_query($_sqlstr);
}//end.open_mssql;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//4.2.执行不返回结果集的SQL语句
/*
调用方法:
1.access:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
2.MySQL:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function execute($_sqlstr,$_conn = null){
$this->sqlstr = $_sqlstr;
if($this->debug) echo "<br>SQL: " . $_sqlstr;
$this->bof = false;
$this->eof = false;
switch($this->dbClass){
case "access":
$this->exec_access($_sqlstr);
break;
case "mysql":
$this->exec_mysql($_sqlstr,$_conn);
break;
//case "mysql_db":
// $this->exec_db_mysql($_sqlstr,$_conn);
case "mssql":
$this->exec_mssql($_sqlstr,$_conn);
break;
default:
break;
}//end.switch;
}//end.execute;
//4.2.1.access.执行不返回结果集的SQL语句
function exec_access(&$_sqlstr){
$this->conn->Execute($_sqlstr);
}//end.exec_access;
//4.2.2.1.MySQL.执行不返回结果集的SQL语句
function exec_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
@mysql_query($_sqlstr,$_conn);
else
@mysql_query($_sqlstr);
}//end.exec_mysql;
//4.2.2.2.MySQL.执行不返回结果集的SQL语句
/*
function exec_db_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
$info = @mysql_query($this->args[0],$this->args[1],$this->args[2]);
else
$info = @mysql_query($this->args[0],$this->args[1]);
}//end.exec_mysql;
*/
//4.2.3.MS SQL.执行不返回结果集的SQL语句
function exec_mssql(&$_sqlstr,&$_conn){
if(isset($_conn))
@mysql_query($_sqlstr,$_conn);
else
@mysql_query($_sqlstr);
}//end.exec_mssql;
//4.3.执行不返回结果集的SQL语句(简写)
function exec($_args = array()){
$this->execute($_args);
}//end.exec;
#39
系统不让再发了,换个用户再发:
//5.显示结果集 ==================================================
//5.1.返回row式结果集.
/*
调用格式:
语法格式: fetch_row(resource result);
result: 是查询结果集.
fetch_row()是从和指定的结果标识关联的结果集中取得一行数据并作为数组返回。
适用于access,mysql,mssql,odbc.
例5.1.:
require("class/mydbs.class.v2.php");
$acs = new mydbs("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs/dbs77.mdb"));
$rs = $acs->open(array("select * from tmp01"));
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
*/
function &fetch_row(&$_result){
switch($this->dbClass){
case "access":
if($this->accessFetch){
$this->db_access_dataSet_rows($_result);
$this->accessFetch = false;
if(isset($this->dataSet[0])) return $this->dataSet[0];
else return false;
}else{
if(!$this->eof){
return $this->access_fetch_row();
}else{
echo ".end";
$this->accessFetch = true;
$this->bof = true;
$this->eof = false;
return false;
}//end.if;
}//end.if;
break;
case "mysql":
return mysql_fetch_row($_result);
break;
case "mssql":
return mssql_fetch_row($_result);
break;
default:
return false;
break;
}//end.switch;
}//end.&fetch_row;
//5.1.1.将access结果集存入数组中
function db_access_dataSet_rows(&$_rs){
//echo ".run3.";
$num_columns = $_rs->Fields->Count();
for ($i=0; $i < $num_columns; $i++)
$fld[$i] = $_rs->Fields($i);
$count = 0;
while (!$_rs->EOF)
{
for ($i=0; $i < $num_columns; $i++) {
$this->dataSet[$count][$i] = $fld[$i]->value;
//echo ":".$fld[$i]->value ;
}
$count++; //count 自增
$_rs->MoveNext();
}//end.while;
$_rs->Close();
$_rs->Release();
}//end.db_access_dataSet_rows;
//5.1.2.返回access的row式结果集
function access_fetch_row(){
if(isset($this->dataSet[$this->rowcount])){
$this->bof = false;
return $this->dataSet[$this->rowcount++];
}
else{
$this->eof = true;
return false;
}//end.if;
}//end.access_fetch_row;
//5.2.返回Array式结果集 +++++++++++++++++++++++++++++++++++++++++
/*
语法格式:
fetch_array(resource result [, int result_type])
返回根据从结果集取得的行生成的数组,如果没有更多行则返回 FALSE。
fetch_array() 是 fetch_row() 的扩展版本。除了将数据以数字索引方式储存在数组中之外,还可以将数据作为关联索引储存,用字段名作为键名。
fetch_array() 中可选的第二个参数 result_type 是一个常量,可以接受以下值:MYSQL_ASSOC,MYSQL_NUM 和 MYSQL_BOTH。本特性是 mydbs V2.0 beta 1.0.1s 起新加的。本参数的默认值是 MYSQL_BOTH。
说明: 如何使用的是Access数据,同不支持第二个参数.
例5.2.(有些部分参见例5.1.):
$rs = $acs->open(array("select * from tmp01"));
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
*/
function fetch_array(&$_result , $result_type=MYSQL_BOTH){
switch($this->dbClass){
case "access":
if($this->accessFetch){
$this->db_access_dataSet_Array($_result);
$this->accessFetch = false;
if(isset($this->dataSet[0])) return $this->dataSet[0];
else return false;
}else{
if(!$this->eof){
return $this->access_fetch_Array();
}else{
$this->accessFetch = true;
$this->bof = true;
$this->eof = false;
return false;
}//end.if;
}//end.if;
break;
case "mysql":
return mysql_fetch_array($_result,$result_type);
break;
case "mssql":
return mssql_fetch_array($_result,$result_type);
break;
default:
return false;
break;
}//end.switch;
}//end.fetch_array;
//5.2.1.将access结果集存入数组中
function db_access_dataSet_Array(&$_rs){
$num_columns = $_rs->Fields->Count();
for ($i=0; $i < $num_columns; $i++)
$fld[$i] = $_rs->Fields($i);
$count = 0;
while (!$_rs->EOF)
{
for ($i=0; $i < $num_columns; $i++)
$this->dataSet[$count][$fld[$i]->name] = $fld[$i]->value;
$count++; //count 自增
$_rs->MoveNext();
}//end.while;
$_rs->Close();
$_rs->Release();
}//end.db_access_dataSet_Array;
//5.2.2.返回access的array式结果集
function access_fetch_array(){
if(isset($this->dataSet[$this->rowcount])){
$this->bof = false;
return $this->dataSet[$this->rowcount++];
}
else{
$this->eof = true;
return false;
}//end.if;
}//end.access_fetch_array;
//5.3.返回结果集行数 ++++++++++++++++++++++++++++++++++++++++++++
//5.显示结果集 ==================================================
//5.1.返回row式结果集.
/*
调用格式:
语法格式: fetch_row(resource result);
result: 是查询结果集.
fetch_row()是从和指定的结果标识关联的结果集中取得一行数据并作为数组返回。
适用于access,mysql,mssql,odbc.
例5.1.:
require("class/mydbs.class.v2.php");
$acs = new mydbs("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs/dbs77.mdb"));
$rs = $acs->open(array("select * from tmp01"));
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
*/
function &fetch_row(&$_result){
switch($this->dbClass){
case "access":
if($this->accessFetch){
$this->db_access_dataSet_rows($_result);
$this->accessFetch = false;
if(isset($this->dataSet[0])) return $this->dataSet[0];
else return false;
}else{
if(!$this->eof){
return $this->access_fetch_row();
}else{
echo ".end";
$this->accessFetch = true;
$this->bof = true;
$this->eof = false;
return false;
}//end.if;
}//end.if;
break;
case "mysql":
return mysql_fetch_row($_result);
break;
case "mssql":
return mssql_fetch_row($_result);
break;
default:
return false;
break;
}//end.switch;
}//end.&fetch_row;
//5.1.1.将access结果集存入数组中
function db_access_dataSet_rows(&$_rs){
//echo ".run3.";
$num_columns = $_rs->Fields->Count();
for ($i=0; $i < $num_columns; $i++)
$fld[$i] = $_rs->Fields($i);
$count = 0;
while (!$_rs->EOF)
{
for ($i=0; $i < $num_columns; $i++) {
$this->dataSet[$count][$i] = $fld[$i]->value;
//echo ":".$fld[$i]->value ;
}
$count++; //count 自增
$_rs->MoveNext();
}//end.while;
$_rs->Close();
$_rs->Release();
}//end.db_access_dataSet_rows;
//5.1.2.返回access的row式结果集
function access_fetch_row(){
if(isset($this->dataSet[$this->rowcount])){
$this->bof = false;
return $this->dataSet[$this->rowcount++];
}
else{
$this->eof = true;
return false;
}//end.if;
}//end.access_fetch_row;
//5.2.返回Array式结果集 +++++++++++++++++++++++++++++++++++++++++
/*
语法格式:
fetch_array(resource result [, int result_type])
返回根据从结果集取得的行生成的数组,如果没有更多行则返回 FALSE。
fetch_array() 是 fetch_row() 的扩展版本。除了将数据以数字索引方式储存在数组中之外,还可以将数据作为关联索引储存,用字段名作为键名。
fetch_array() 中可选的第二个参数 result_type 是一个常量,可以接受以下值:MYSQL_ASSOC,MYSQL_NUM 和 MYSQL_BOTH。本特性是 mydbs V2.0 beta 1.0.1s 起新加的。本参数的默认值是 MYSQL_BOTH。
说明: 如何使用的是Access数据,同不支持第二个参数.
例5.2.(有些部分参见例5.1.):
$rs = $acs->open(array("select * from tmp01"));
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
*/
function fetch_array(&$_result , $result_type=MYSQL_BOTH){
switch($this->dbClass){
case "access":
if($this->accessFetch){
$this->db_access_dataSet_Array($_result);
$this->accessFetch = false;
if(isset($this->dataSet[0])) return $this->dataSet[0];
else return false;
}else{
if(!$this->eof){
return $this->access_fetch_Array();
}else{
$this->accessFetch = true;
$this->bof = true;
$this->eof = false;
return false;
}//end.if;
}//end.if;
break;
case "mysql":
return mysql_fetch_array($_result,$result_type);
break;
case "mssql":
return mssql_fetch_array($_result,$result_type);
break;
default:
return false;
break;
}//end.switch;
}//end.fetch_array;
//5.2.1.将access结果集存入数组中
function db_access_dataSet_Array(&$_rs){
$num_columns = $_rs->Fields->Count();
for ($i=0; $i < $num_columns; $i++)
$fld[$i] = $_rs->Fields($i);
$count = 0;
while (!$_rs->EOF)
{
for ($i=0; $i < $num_columns; $i++)
$this->dataSet[$count][$fld[$i]->name] = $fld[$i]->value;
$count++; //count 自增
$_rs->MoveNext();
}//end.while;
$_rs->Close();
$_rs->Release();
}//end.db_access_dataSet_Array;
//5.2.2.返回access的array式结果集
function access_fetch_array(){
if(isset($this->dataSet[$this->rowcount])){
$this->bof = false;
return $this->dataSet[$this->rowcount++];
}
else{
$this->eof = true;
return false;
}//end.if;
}//end.access_fetch_array;
//5.3.返回结果集行数 ++++++++++++++++++++++++++++++++++++++++++++
#40
//6.查询分页 ====================================================
//6.1.设置查询分页 ----------------------------------------------
//6.1.1.设置每页行数
function &setPage_Linage($_Linage = 0){
$this->Linage = $_Linage;
if($_Linage>0) $this->count_MaxPage();
else $this->MaxPage = 1;
}//end.setPage_Linage;
//6.1.2.计算总页数 ----------------------------------------------
function &count_MaxPage(){
$sqltmp = $this->sqlstr;
$sql = preg_replace(array ("'select.*?from'si","'order by.*'"), array ("select count(*), count(*)/$this->Linage from "," "), $sqltmp);
$rs = $this->open($sql);
while($r = $this->fetch_row($rs)){
$this->MaxCount = $r[0];
$this->MaxPage = $r[1];
}//end.while;
$this->MaxPage = ceil($this->MaxPage); //存储页数
$this->sqlstr = $sqltmp ;
}//end.count_MaxPage;
//6.1.3.设置当前页号 --------------------------------------------
function &setPage_CurrentPage($_CurrentPage = 1){
if($_CurrentPage<=1){
$this->CurrentPage = 1;
}else{
if($_CurrentPage>$this->MaxPage) $this->CurrentPage = $this->MaxPage;
else $this->CurrentPage = $_CurrentPage;
}//end.if;
//return $this->CurrentPage;
}//end.setPage_CurrentPage;
//6.1.4.计算偏移量 ----------------------------------------------
function &count_Offset($_CurrentPage = 0, $_Linage = 0){
/*if($_Linage>0){
$this->Linage = $_Linage;
$this->count_MaxPage(); //修改后要重新计算总页数.
}else{
if(($this->MaxPage<=0)&&($this->MaxCount>0)) //如果尚未计算总页数,则计算总页数
$this->count_MaxPage(); //重新计算总页数
}//end.if;
if($_CurrentPage<>0) $this->CurrentPage = $_CurrentPage;
else $this->CurrentPage = 0;*/
$this->offset = $_Linage * ($_CurrentPage - 1);
//return $this->offset;
}//end.count_Offset;
function &SelectLimit($_sqlstr=null,$_CurrentPage=0,$_Linage=0,$_style=0){
$this->sqlstr = $_sqlstr;
//$this->count_MaxPage($_sqlstr);
$this->count_Offset($_CurrentPage,$_Linage); //计算偏移量
if( $_Linage > 0 ) $this->setPage_Linage($_Linage);
if( $_CurrentPage > 0 ) $this->CurrentPage = $this->setPage_CurrentPage($_CurrentPage);
switch($this->dbClass){
case "access":
return $this->AccessSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
case "mysql":
return $this->MySQLSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
case "mssql":
return $this->MSSQLSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
default:
return false;
break;
}//end.switch;
}//end.&SelectLimit;
//6.2.1.Access分页查询
function &AccessSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
$sqltmp = preg_replace("'^select'","select top $_Linage",$sqltmp);
if($this->offset>0)
$sqlClause = preg_replace("'^select.*from'","id <> all(select top $this->offset id from",$sqltmp).")";
if($this->offset>0){
$sqltmp = preg_replace("'where '" ,"where ($sqlClause) and ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp = preg_replace("'order by '"," where $sqlClause order by ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp .= " where $sqlClause ";
}
return $this->open($sqltmp);
/* while(!$rs->EOF){
$a1 = $rs->fields("id");
$a2 = $rs->fields("name");
echo "<br>*.".$a1->value." - ".$a2->value;
$rs->MoveNext();
}
*/
}//end.&AccessSelectLimit;
//6.2.2.MySQL分页查询
function &MySqlSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
if(strspn("LIMIT",$sqltmp)==0){
$sqltmp .= " LIMIT $this->offset,$_Linage)";
}//end.if;
return $this->open($sqltmp);
}//end.&MySqlSelectLimit;
//6.2.3.MS SQL分页查询
function &MSSqlSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
$sqltmp = preg_replace("'^select'","select top $_Linage",$sqltmp);
if($this->offset>0)
$sqlClause = preg_replace("'^select.*from'","id <> all(select top $this->offset id from",$sqltmp).")";
if($this->offset>0){
$sqltmp = preg_replace("'where '" ,"where ($sqlClause) and ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp = preg_replace("'order by '"," where $sqlClause order by ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp .= " where $sqlClause ";
}
return $this->open($sqltmp);
}//end.&MSSqlSelectLimit;
//6.1.设置查询分页 ----------------------------------------------
//6.1.1.设置每页行数
function &setPage_Linage($_Linage = 0){
$this->Linage = $_Linage;
if($_Linage>0) $this->count_MaxPage();
else $this->MaxPage = 1;
}//end.setPage_Linage;
//6.1.2.计算总页数 ----------------------------------------------
function &count_MaxPage(){
$sqltmp = $this->sqlstr;
$sql = preg_replace(array ("'select.*?from'si","'order by.*'"), array ("select count(*), count(*)/$this->Linage from "," "), $sqltmp);
$rs = $this->open($sql);
while($r = $this->fetch_row($rs)){
$this->MaxCount = $r[0];
$this->MaxPage = $r[1];
}//end.while;
$this->MaxPage = ceil($this->MaxPage); //存储页数
$this->sqlstr = $sqltmp ;
}//end.count_MaxPage;
//6.1.3.设置当前页号 --------------------------------------------
function &setPage_CurrentPage($_CurrentPage = 1){
if($_CurrentPage<=1){
$this->CurrentPage = 1;
}else{
if($_CurrentPage>$this->MaxPage) $this->CurrentPage = $this->MaxPage;
else $this->CurrentPage = $_CurrentPage;
}//end.if;
//return $this->CurrentPage;
}//end.setPage_CurrentPage;
//6.1.4.计算偏移量 ----------------------------------------------
function &count_Offset($_CurrentPage = 0, $_Linage = 0){
/*if($_Linage>0){
$this->Linage = $_Linage;
$this->count_MaxPage(); //修改后要重新计算总页数.
}else{
if(($this->MaxPage<=0)&&($this->MaxCount>0)) //如果尚未计算总页数,则计算总页数
$this->count_MaxPage(); //重新计算总页数
}//end.if;
if($_CurrentPage<>0) $this->CurrentPage = $_CurrentPage;
else $this->CurrentPage = 0;*/
$this->offset = $_Linage * ($_CurrentPage - 1);
//return $this->offset;
}//end.count_Offset;
function &SelectLimit($_sqlstr=null,$_CurrentPage=0,$_Linage=0,$_style=0){
$this->sqlstr = $_sqlstr;
//$this->count_MaxPage($_sqlstr);
$this->count_Offset($_CurrentPage,$_Linage); //计算偏移量
if( $_Linage > 0 ) $this->setPage_Linage($_Linage);
if( $_CurrentPage > 0 ) $this->CurrentPage = $this->setPage_CurrentPage($_CurrentPage);
switch($this->dbClass){
case "access":
return $this->AccessSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
case "mysql":
return $this->MySQLSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
case "mssql":
return $this->MSSQLSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
default:
return false;
break;
}//end.switch;
}//end.&SelectLimit;
//6.2.1.Access分页查询
function &AccessSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
$sqltmp = preg_replace("'^select'","select top $_Linage",$sqltmp);
if($this->offset>0)
$sqlClause = preg_replace("'^select.*from'","id <> all(select top $this->offset id from",$sqltmp).")";
if($this->offset>0){
$sqltmp = preg_replace("'where '" ,"where ($sqlClause) and ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp = preg_replace("'order by '"," where $sqlClause order by ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp .= " where $sqlClause ";
}
return $this->open($sqltmp);
/* while(!$rs->EOF){
$a1 = $rs->fields("id");
$a2 = $rs->fields("name");
echo "<br>*.".$a1->value." - ".$a2->value;
$rs->MoveNext();
}
*/
}//end.&AccessSelectLimit;
//6.2.2.MySQL分页查询
function &MySqlSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
if(strspn("LIMIT",$sqltmp)==0){
$sqltmp .= " LIMIT $this->offset,$_Linage)";
}//end.if;
return $this->open($sqltmp);
}//end.&MySqlSelectLimit;
//6.2.3.MS SQL分页查询
function &MSSqlSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
$sqltmp = preg_replace("'^select'","select top $_Linage",$sqltmp);
if($this->offset>0)
$sqlClause = preg_replace("'^select.*from'","id <> all(select top $this->offset id from",$sqltmp).")";
if($this->offset>0){
$sqltmp = preg_replace("'where '" ,"where ($sqlClause) and ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp = preg_replace("'order by '"," where $sqlClause order by ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp .= " where $sqlClause ";
}
return $this->open($sqltmp);
}//end.&MSSqlSelectLimit;
#41
//7.完成较复杂的插入语句 ========================================
function &InsertAdd($_sql1,$_sql2,$_class="char",$_TableName=""){
if(($_sql1!="")&&($_sql2=="")){
return false;
}else{
switch($_class){
case "char":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "int":
$this->sql1 .= $_sql1.",";
$this->sql2 .= $_sql2.",";
break;
case "text":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "date":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "datetime":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "time":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "$":
$this->sql1 .= $_sql1.",";
$this->sql2 .= $_sql2.",";
break;
case "exec":
if($_TableName <> ""){
$_sql1 = preg_replace("',$'","",$this->sql1);
$_sql2 = preg_replace("',$'","",$this->sql2);
$this->sql1 = "insert into ". $_TableName ."(" . $_sql1 . ")";
$this->sql2 = " values(" . $_sql2 . ")";
//echo "=+".$this->sql1 . $this->sql2 ."+=";
$this->execute($this->sql1 . $this->sql2);
return true;
}
break;
default:
return false;
break;
}//end.switch;
}//end.if;
}//end.&insert;
function &InsertAdd($_sql1,$_sql2,$_class="char",$_TableName=""){
if(($_sql1!="")&&($_sql2=="")){
return false;
}else{
switch($_class){
case "char":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "int":
$this->sql1 .= $_sql1.",";
$this->sql2 .= $_sql2.",";
break;
case "text":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "date":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "datetime":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "time":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "$":
$this->sql1 .= $_sql1.",";
$this->sql2 .= $_sql2.",";
break;
case "exec":
if($_TableName <> ""){
$_sql1 = preg_replace("',$'","",$this->sql1);
$_sql2 = preg_replace("',$'","",$this->sql2);
$this->sql1 = "insert into ". $_TableName ."(" . $_sql1 . ")";
$this->sql2 = " values(" . $_sql2 . ")";
//echo "=+".$this->sql1 . $this->sql2 ."+=";
$this->execute($this->sql1 . $this->sql2);
return true;
}
break;
default:
return false;
break;
}//end.switch;
}//end.if;
}//end.&insert;
#42
///20.session功能
//20.1.创建session功能表
function CreateLoginInfoTable(){
switch($this->dbClass){
case "access":
$sql = "create table SessionLoginInfo(userid varchar(50) not null primary key, sessionid varchar(50), IP char(20) , logintime datetime, mm int)";
break;
case "mysql":
$sql = "create table SessionLoginInfo(userid varchar(50) not null, sessionid varchar(50) not null,IP char(20),logintime datetime,mm bigint(20),primary key (userid))";
break;
case "mssql":
$sql = "create table SessionLoginInfo(userid varchar(50) not null primary key, sessionid varchar(50), IP char(20) , logintime datetime, mm bigint)";
break;
default:
$sql = "";
break;
}//end.switch;
$this->execute($sql);
}//end.CreateLoginInfoTable;
//20.2.写入登录者
function &setSessionLoginInfo($_userid,$_sessionid,$_ip,$_datetime,$_mm){
if($row=$this->getSessionLoginInfo($_userid)){
$sessionid = $row["sessionid"];
$mm = $row["mm"];
$ip = $row["IP"];
if($sessionid == $_sessionid){
$_datetime = date("Y-m-d H:i");
$_mm = (int)(date("U")/60);
$sql = "update SessionLoginInfo set mm = $_mm where userid = '$_userid'";
$this->execute($sql);
return true;
}else{
return false;
}//end.if;
}else{
$_mm = (int)($_mm/60);
$sql = "insert into SessionLoginInfo(userid,sessionid,ip,logintime,mm) values('$_userid','$_sessionid','$_ip','$_datetime',$_mm)";
$this->execute($sql);
return true;
}//end.if;
}//end.&setSessionLoginInfo;
//20.3.读出登录者
function &getSessionLoginInfo($_userid){
$sql = "select * from SessionLoginInfo where userid = '$_userid'";
$rs = $this->open($sql);
if($row = $this->fetch_array($rs)) return $row;
else return false;
}//end.&getSessionLoginInfo;
//20.4.刷新登录信息库
function &FlashSessionLoginInfo(){
$mm = (int)(date("U")/60);
$sql = "delete from SessionLoginInfo where $mm - mm > $this->SessionTime";
$this->execute($sql);
}//end.&FlashSessionLoginInf;
//20.5.注销登录信息
function &LogoutSessionLoginInfo($_userid){
$sql = "delete from SessionLoginInfo where userid = '$_userid'";
$this->execute($sql);
}//end.
}//end.class.mydbs.
?>
//20.1.创建session功能表
function CreateLoginInfoTable(){
switch($this->dbClass){
case "access":
$sql = "create table SessionLoginInfo(userid varchar(50) not null primary key, sessionid varchar(50), IP char(20) , logintime datetime, mm int)";
break;
case "mysql":
$sql = "create table SessionLoginInfo(userid varchar(50) not null, sessionid varchar(50) not null,IP char(20),logintime datetime,mm bigint(20),primary key (userid))";
break;
case "mssql":
$sql = "create table SessionLoginInfo(userid varchar(50) not null primary key, sessionid varchar(50), IP char(20) , logintime datetime, mm bigint)";
break;
default:
$sql = "";
break;
}//end.switch;
$this->execute($sql);
}//end.CreateLoginInfoTable;
//20.2.写入登录者
function &setSessionLoginInfo($_userid,$_sessionid,$_ip,$_datetime,$_mm){
if($row=$this->getSessionLoginInfo($_userid)){
$sessionid = $row["sessionid"];
$mm = $row["mm"];
$ip = $row["IP"];
if($sessionid == $_sessionid){
$_datetime = date("Y-m-d H:i");
$_mm = (int)(date("U")/60);
$sql = "update SessionLoginInfo set mm = $_mm where userid = '$_userid'";
$this->execute($sql);
return true;
}else{
return false;
}//end.if;
}else{
$_mm = (int)($_mm/60);
$sql = "insert into SessionLoginInfo(userid,sessionid,ip,logintime,mm) values('$_userid','$_sessionid','$_ip','$_datetime',$_mm)";
$this->execute($sql);
return true;
}//end.if;
}//end.&setSessionLoginInfo;
//20.3.读出登录者
function &getSessionLoginInfo($_userid){
$sql = "select * from SessionLoginInfo where userid = '$_userid'";
$rs = $this->open($sql);
if($row = $this->fetch_array($rs)) return $row;
else return false;
}//end.&getSessionLoginInfo;
//20.4.刷新登录信息库
function &FlashSessionLoginInfo(){
$mm = (int)(date("U")/60);
$sql = "delete from SessionLoginInfo where $mm - mm > $this->SessionTime";
$this->execute($sql);
}//end.&FlashSessionLoginInf;
//20.5.注销登录信息
function &LogoutSessionLoginInfo($_userid){
$sql = "delete from SessionLoginInfo where userid = '$_userid'";
$this->execute($sql);
}//end.
}//end.class.mydbs.
?>
#43
过了这么久,有测评么?
#44
我以前也写不过觉得没有成熟的代码好啊!比如phplib
#45
可以拆分成几个类,不同的功能分到不同的类里面
#46
想看看guye99@163.com
#47
你强.............我顶..............
#48
发过来看看呐!
hjmsoalr@163.com
hjmsoalr@163.com
#49
meng.chao@163.com
#50
wind619@126.com 谢谢
#1
no text
#2
请留邮件!
#3
我来看看,谢了!kinderhuang@hotmail.com
#4
3Q: mydll@163.com
#5
关注 haidazhang@163.com
#6
zyj@wmdf.cn
#7
tfhxg@163.com
#8
大家有什么建议没有啊?
#9
大家别忘了给测评,打分!
#10
晕 没收到谈何建议
#11
刚刚重发了,请查收!
#12
<?php
////简单实例:
require("class/mydbsClass.php");
session_start();
$acs = new mydb("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs.mdb"));
$acs->debug = true;
//1.1.select+fetch_row
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
echo "</table>";
//1.2.select+fetch_array
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//2.插入/更新/删除/...
$acs->execute("insert into tmp01(name) values('姓名')");
//3.分页
$rs = $acs->SelectLimit("select * from tmp01 order by id",2,10);
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//4.session
$acs->CreateLoginInfoTable();//创建,只能做一次
$acs->FlashSessionLoginInfo();//刷新
echo "<br>:".$acs->setSessionLoginInfo(用户ID,session_id(),IP地址,date("Y-m-d H:i"),date("U")); //设置
?>
////简单实例:
require("class/mydbsClass.php");
session_start();
$acs = new mydb("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs.mdb"));
$acs->debug = true;
//1.1.select+fetch_row
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
echo "</table>";
//1.2.select+fetch_array
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//2.插入/更新/删除/...
$acs->execute("insert into tmp01(name) values('姓名')");
//3.分页
$rs = $acs->SelectLimit("select * from tmp01 order by id",2,10);
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//4.session
$acs->CreateLoginInfoTable();//创建,只能做一次
$acs->FlashSessionLoginInfo();//刷新
echo "<br>:".$acs->setSessionLoginInfo(用户ID,session_id(),IP地址,date("Y-m-d H:i"),date("U")); //设置
?>
#13
各位收到没有? 有问题请回复!
#14
根据实例谈点感受
$acs = new mydb("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs.mdb"));
$acs->debug = true;
*** 最好能简化成
$acs = new mydb("access:dbname=dbs.mdb", $username, $password);
//1.1.select+fetch_row
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
echo "</table>";
*** open方法易产生歧异,宜改为query或select
//1.2.select+fetch_array
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//2.插入/更新/删除/...
$acs->execute("insert into tmp01(name) values('姓名')");
*** execute方法就一定不执行select指令吗?
//3.分页
$rs = $acs->SelectLimit("select * from tmp01 order by id",2,10);
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
*** 没有all方法吗?你都需要一条一条记录处理吗?
//4.session
$acs->CreateLoginInfoTable();//创建,只能做一次
$acs->FlashSessionLoginInfo();//刷新
echo "<br>:".$acs->setSessionLoginInfo(用户ID,session_id(),IP地址,date("Y-m-d H:i"),date("U")); //设置
*** CreateLoginInfoTable宜自动完成
$acs = new mydb("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs.mdb"));
$acs->debug = true;
*** 最好能简化成
$acs = new mydb("access:dbname=dbs.mdb", $username, $password);
//1.1.select+fetch_row
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
echo "</table>";
*** open方法易产生歧异,宜改为query或select
//1.2.select+fetch_array
$rs = $acs->open("select * from uses");
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
//2.插入/更新/删除/...
$acs->execute("insert into tmp01(name) values('姓名')");
*** execute方法就一定不执行select指令吗?
//3.分页
$rs = $acs->SelectLimit("select * from tmp01 order by id",2,10);
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
echo "</table>";
*** 没有all方法吗?你都需要一条一条记录处理吗?
//4.session
$acs->CreateLoginInfoTable();//创建,只能做一次
$acs->FlashSessionLoginInfo();//刷新
echo "<br>:".$acs->setSessionLoginInfo(用户ID,session_id(),IP地址,date("Y-m-d H:i"),date("U")); //设置
*** CreateLoginInfoTable宜自动完成
#15
lch-1983@163.com
瞧一瞧,看一看
瞧一瞧,看一看
#16
xuzuning(唠叨) 的意见不错,不过我有以下问题:
*** 没有all方法吗?你都需要一条一条记录处理吗?
是什么意思?能不能说详细些,我还不大明白.
*** CreateLoginInfoTable宜自动完成
我这样考虑的,如果自动创建的话,则每次都要加判断,会影响速度!
*** 没有all方法吗?你都需要一条一条记录处理吗?
是什么意思?能不能说详细些,我还不大明白.
*** CreateLoginInfoTable宜自动完成
我这样考虑的,如果自动创建的话,则每次都要加判断,会影响速度!
#17
qinkui7@126.com
看看
看看
#18
alfredzeng@gmail.com
学习
学习
#19
大家别忘了给测评,打分!
#20
*** 没有all方法吗?你都需要一条一条记录处理吗?
是什么意思?能不能说详细些,我还不大明白.
一次读取全部查询结果到数组
是什么意思?能不能说详细些,我还不大明白.
一次读取全部查询结果到数组
#21
明白了,待我改进一下.
#22
请问:xuzuning(唠叨)
*** CreateLoginInfoTable宜自动完成
应该怎么做呢?
*** CreateLoginInfoTable宜自动完成
应该怎么做呢?
#23
zhizhi@265.com 观摩一下哈
#24
*** CreateLoginInfoTable宜自动完成
应该怎么做呢?
其实,当不是自动完成的时候,你并不能保证在session表建立以后就不会有
$asc->CreateLoginInfoTable();
出现
于是你依然是要在CreateLoginInfoTable方法中判断session表是否已被建立
所以可在类初始化的时候执行CreateLoginInfoTable
应该怎么做呢?
其实,当不是自动完成的时候,你并不能保证在session表建立以后就不会有
$asc->CreateLoginInfoTable();
出现
于是你依然是要在CreateLoginInfoTable方法中判断session表是否已被建立
所以可在类初始化的时候执行CreateLoginInfoTable
#25
初始化时如果要建立表的话,那么就会出现有可能表已经存在的问题.
那应该如何来判断呢?
那应该如何来判断呢?
#26
检查数据库中是否存在某个表,对于不同的数据库有不同的指令。
你可以参考adodb的MetaDatabases方法中的代码
简单的写法是利用错误处理机制,设表名为tbl_name
if(! @xxx_query('select * from tbl_name where 1=0'))
//表不存在的处理代码
当表不存在的时候 select * from tbl_name where 1=0 将会出错并返回假
由于@屏蔽了错误信息,所以错误信息是不会显示的
你可以参考adodb的MetaDatabases方法中的代码
简单的写法是利用错误处理机制,设表名为tbl_name
if(! @xxx_query('select * from tbl_name where 1=0'))
//表不存在的处理代码
当表不存在的时候 select * from tbl_name where 1=0 将会出错并返回假
由于@屏蔽了错误信息,所以错误信息是不会显示的
#27
十分感谢 xuzuning(唠叨)
我有不断完善这个类的.
我有不断完善这个类的.
#28
function MetaDatabases()
{
global $ADODB_FETCH_MODE;
if ($this->metaDatabasesSQL) {
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
$arr = $this->GetCol($this->metaDatabasesSQL);
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
return $arr;
}
return false;
}
ADODB中的这段代码我有些地方看不懂.
SetFetchMode($savem); 是什么意思?
{
global $ADODB_FETCH_MODE;
if ($this->metaDatabasesSQL) {
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
$arr = $this->GetCol($this->metaDatabasesSQL);
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
return $arr;
}
return false;
}
ADODB中的这段代码我有些地方看不懂.
SetFetchMode($savem); 是什么意思?
#29
fanglibang@163.com
#30
zalvsa@163.com
#31
根据fetch mode来实现取的时候是以数字做索引还是字段名做索引
mysql有两种 MYSQL_NUM, MYSQL_ASSOC
你看看mysql_fetch_array函数的定义就知道了
mysql有两种 MYSQL_NUM, MYSQL_ASSOC
你看看mysql_fetch_array函数的定义就知道了
#32
这个类中两种都支持
以数字为索引:
while($r = $acs->fetch_now($rs)){
echo $r[0].$r[1];
}
以字段做索引:
while($r = $acs->fetch_array($rs)){
echo $r["id"].$r["name"];
}
以数字为索引:
while($r = $acs->fetch_now($rs)){
echo $r[0].$r[1];
}
以字段做索引:
while($r = $acs->fetch_array($rs)){
echo $r["id"].$r["name"];
}
#33
fj_1@126.com
#34
fj_1@tom.com.误写..呵呵.
#35
jdhsd@sohu.com
#36
现在把类代码贴出来吧:
第一部分:
<?php
/*
请您保留以下信息.
数据库操作公共类 V2.0 beta 2.0.5 版
版本所有:张洋软件工作室(C)
TEL: 130????7627
QQ: 47488357
E-Mail:117zy@sohu.com
2005.10
可操作数据库: access,mysql,mssql
版本说明:
1.2005.10.13,V1.0版:
v1.0版,可以执行access,MYSQL,MSSQL三个版本.
可以执行SQL语句.
2.2005.10.15 V2.0 beta 2.0.1版:
在1.0版基础,新增了更多参数设置功能.
3.2005.10.16 V2.0 beta 2.0.2版:
在beta 2.0.1版基础上,改进了fetch_row()和fetch_array(),使各种数据库统一使用一种回显.
4.2005.10.18 V2.0 beta 2.0.3版:
在beta 2.0.2版基础上,增加了SelectLimit函数,实现了简单的分页程序.
增加了$this->debug显示调试.
5.2005.10.21 V2.0 beta 2.0.4版
在beta 2.0.3版基础上,增加了InsertAdd函数,实现了较复杂的插入.
6.2005.10.23 V2.0 beta 2.0.5版
在beta 2.0.4版基础上,增加了Session在查登录功能.
*/
class mydb{
var $dbClass; //数据库类型.access:mysql:mssql;
var $conn; //连接
var $dbName; //数据库名称
var $sqlstr; //SQL语句
var $info; //信息
var $args = array();
var $rowcount; //结果集指针
var $dataSet = array(); //数据结果集
var $bof; //开始标志
var $eof; //结束标志
var $accessFetch; //结果集读取标志
var $runtime; //测试运行时间
var $debug; //测试设置,默认值:false
// 翻页参数设置
var $CurrentPage; //当前页号
var $MaxPage; //最大页号
var $Linage; //每页行数
var $PaginalFormat; //翻页样式
var $MaxCount; //记录总数(指查询返回数)
var $offset; //偏移量,指记录的开始
//
var $sql1; //
var $sql2; //
//session设置
var $SessionTime; //$Session保存时间,分
//1.设置 ========================================================
//1.1.构造
function mydbs($_dbClass="access"){
$this->dbClass = $_dbClass;
$this->rowcount = 0;
$this->eof = false;
$this->bof = false;
$this->accessFetch = true;
$this->debug = false;
//设置分页参数
$this->CurrentPage = 1;
$this->MaxPage = 1;
$this->MaxCount = 1;
$this->Linage = 0;
//设置session
$this->SessionTime = 5;
}//end.mydbs;
//1.2.设置数据库类型
function setDbClass(&$_dbClass){
$this->dbClass = $_dbClass;
}//end.setDbClass;
//0.0.释放 ------------------------------------------------------
function db_close($_args = array()){
switch($this->dbClass){
case "access":
break;
case "mysql":
if(isset($_args[0])) return @mysql_close($_args[0]);
else return @mysql_close();
break;
case "mssql":
if(isset($_args[0])) return @mssql_close($_args[0]);
else return @mssql_close();
break;
}//end.switch;
}//end.db_close;
第一部分:
<?php
/*
请您保留以下信息.
数据库操作公共类 V2.0 beta 2.0.5 版
版本所有:张洋软件工作室(C)
TEL: 130????7627
QQ: 47488357
E-Mail:117zy@sohu.com
2005.10
可操作数据库: access,mysql,mssql
版本说明:
1.2005.10.13,V1.0版:
v1.0版,可以执行access,MYSQL,MSSQL三个版本.
可以执行SQL语句.
2.2005.10.15 V2.0 beta 2.0.1版:
在1.0版基础,新增了更多参数设置功能.
3.2005.10.16 V2.0 beta 2.0.2版:
在beta 2.0.1版基础上,改进了fetch_row()和fetch_array(),使各种数据库统一使用一种回显.
4.2005.10.18 V2.0 beta 2.0.3版:
在beta 2.0.2版基础上,增加了SelectLimit函数,实现了简单的分页程序.
增加了$this->debug显示调试.
5.2005.10.21 V2.0 beta 2.0.4版
在beta 2.0.3版基础上,增加了InsertAdd函数,实现了较复杂的插入.
6.2005.10.23 V2.0 beta 2.0.5版
在beta 2.0.4版基础上,增加了Session在查登录功能.
*/
class mydb{
var $dbClass; //数据库类型.access:mysql:mssql;
var $conn; //连接
var $dbName; //数据库名称
var $sqlstr; //SQL语句
var $info; //信息
var $args = array();
var $rowcount; //结果集指针
var $dataSet = array(); //数据结果集
var $bof; //开始标志
var $eof; //结束标志
var $accessFetch; //结果集读取标志
var $runtime; //测试运行时间
var $debug; //测试设置,默认值:false
// 翻页参数设置
var $CurrentPage; //当前页号
var $MaxPage; //最大页号
var $Linage; //每页行数
var $PaginalFormat; //翻页样式
var $MaxCount; //记录总数(指查询返回数)
var $offset; //偏移量,指记录的开始
//
var $sql1; //
var $sql2; //
//session设置
var $SessionTime; //$Session保存时间,分
//1.设置 ========================================================
//1.1.构造
function mydbs($_dbClass="access"){
$this->dbClass = $_dbClass;
$this->rowcount = 0;
$this->eof = false;
$this->bof = false;
$this->accessFetch = true;
$this->debug = false;
//设置分页参数
$this->CurrentPage = 1;
$this->MaxPage = 1;
$this->MaxCount = 1;
$this->Linage = 0;
//设置session
$this->SessionTime = 5;
}//end.mydbs;
//1.2.设置数据库类型
function setDbClass(&$_dbClass){
$this->dbClass = $_dbClass;
}//end.setDbClass;
//0.0.释放 ------------------------------------------------------
function db_close($_args = array()){
switch($this->dbClass){
case "access":
break;
case "mysql":
if(isset($_args[0])) return @mysql_close($_args[0]);
else return @mysql_close();
break;
case "mssql":
if(isset($_args[0])) return @mssql_close($_args[0]);
else return @mssql_close();
break;
}//end.switch;
}//end.db_close;
#37
//2.连接 ========================================================
//2.0.连接
/*
调用方法:
1.Access:
格式: db_connect(array([string server_name[,int codepage]]));
server_name: DCOM 服务器的名字,组件在此服务器上被取用。如果是 NULL,则假定是 localhost。想要允许 DCOM,必须将 php.ini 中的 com.allow_dcom 设为 TRUE。
codepage: 指定用于将 PHP 字符串(php-strings)转换成 UNICODE 字符串(unicode-strings)的代码页,反之亦然。可用的值为 CP_ACP、CP_MACCP、CP_OEMCP、CP_SYMBOL、CP_THREAD_ACP, CP_UTF7 和 CP_UTF8。
-----------------------------------------------------------------
2.MySQL:
格式: db_connect(array([string server [, string username [, string password [, bool new_link [, int client_flags]]]]]));
建立一个到 MySQL 服务器的连接。当没有提供可选参数时使用以下默认值:server = 'localhost:3306',username = 服务器进程所有者的用户名,password = 空密码。
server 参数可以包括端口号。例如 "hostname:port" 或者是到本地套接字的路径,例如本机上的 ":/path/to/socket"。
注: 无论指定 "localhost" 或者 "localhost:port" 作为 server,MySQL 客户端库将覆盖之并尝试连接到本地套接字(Windows 中的名字管道)。如果希望使用 TCP/IP 连接,用 "127.0.0.1" 替代 "localhost"。如果 MySQL 客户端库试图连接到错误的本地套接字,则应该在 PHP 配置中将 mysql.default_host 设为正确的路径并使 server 字段为空。
":port" 的支持是 PHP 3.0B4 起加入的。
":/path/to/socket" 的支持是 PHP 3.0.10 起加入的。
-----------------------------------------------------------------
3.MS SQL:
格式: db_connect(array([string servername [, string username [, string password]]]));
servername : 服务器名.
username: 用户名.
password: 密码.
-----------------------------------------------------------------
*/
function db_connect($_args = array()){
$this->args = $_args;
switch($this->dbClass){
case "access":
$this->access_db_connect();
return $this->conn;
break;
case "mysql":
$this->mysql_db_connect();
return $this->conn;
break;
case "mssql":
$this->mssql_db_connect();
return $this->conn;
break;
default:
return false;
break;
}//end.switch;
}//end.db_connect;
//2.1.连接Access
function access_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @new COM("ADODB.Connection");
break;
case 1:
$this->conn = @new COM("ADODB.Connection",$this->args[0]);
break;
case 2:
$this->conn = @new COM("ADODB.Connection",$this->args[0],$this->args[1]);
break;
default:
$this->conn = false;
break;
}//end.switch;
}//end.access_db_connect;
//2.2.1.连接MySQL
function mysql_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @mysql_connect();
break;
case 1:
$this->conn = @mysql_connect($this->args[0]);
break;
case 2:
$this->conn = @mysql_connect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2]);
break;
case 4:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2],$this->args[3]);
break;
case 5:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2],$this->args[3],$this->args[4]);
break;
default:
return false;
break;
}
}//end.mysql_db_connect;
//2.2.2.连接MySQL
function mysql_db_pconnect(){
switch(count($this->args)){
case 0:
$this->conn = @mysql_pconnect();
break;
case 1:
$this->conn = @mysql_pconnect($this->args[0]);
break;
case 2:
$this->conn = @mysql_pconnect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mysql_pconnect($this->args[0],$this->args[1],$this->args[2]);
break;
default:
$this->conn = false;
break;
}
}//end.mysql_db_connect;
//2.3.连接MS SQL
function mssql_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @mssql_connect();
break;
case 1:
$this->conn = @mssql_connect($this->args[0]);
break;
case 2:
$this->conn = @mssql_connect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mssql_connect($this->args[0],$this->args[1],$this->args[2]);
break;
default:
$this->conn = false;
break;
}
}//end.mssql_db_connect;
//3.选择数据库 ==================================================
//3.1.选择数据库
/*
调用方法:
1.access:
格式: select_db(array(string dbName [, string UserID [, string Password]]))
dbName : 数据库名(相对路径+数据库名)
UserID : 用户ID
Password : 密码
-----------------------------------------------------------------
2.MySQL:
格式: select_db(array(string database_name [, resource link_identifier]))
database_name : 数据库名
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: select_db(array(string database_name [, resource link_identifier]))
database_name : 数据库名
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function select_db($_args = array()){
$this->args = $_args;
switch($this->dbClass){
case "access":
$this->db_access_select_db();
return $this->conn;
break;
case "mysql":
return $this->db_mysql_select_db();
break;
case "mssql":
return $this->db_mssql_select_db();
break;
default:
break;
}//end.switch;
}//end.select_db;
//3.2.access选择数据库
function db_access_select_db(){
switch(count($this->args)){
case 1:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";";
$this->conn->open($dsn);
break;
case 2:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";UID=".$this->args[1].";";
$this->conn->open($dsn);
break;
case 3:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";UID=".$this->args[1].";Pwd=".$this->args[2].";";
$this->conn->open($dsn);
break;
default:
return false;
break;
}//end.switch;
}//end.
//3.3.MySQL选择数据库
function db_mysql_select_db(){
if(isset($this->args[1])) return @mysql_select_db($this->args[0],$this->args[1]);
else return @mysql_select_db($this->args[0]);
}//end.db_mysql_select_db;
//3.4.MsSQL选择数据库
function db_mssql_select_db($_args = array()){
if(isset($this->args[1])) return @mssql_select_db($this->args[0],$this->args[1]);
else return @mssql_select_db($this->args[0]);
}//end.db_mysql_select_db;
//2.0.连接
/*
调用方法:
1.Access:
格式: db_connect(array([string server_name[,int codepage]]));
server_name: DCOM 服务器的名字,组件在此服务器上被取用。如果是 NULL,则假定是 localhost。想要允许 DCOM,必须将 php.ini 中的 com.allow_dcom 设为 TRUE。
codepage: 指定用于将 PHP 字符串(php-strings)转换成 UNICODE 字符串(unicode-strings)的代码页,反之亦然。可用的值为 CP_ACP、CP_MACCP、CP_OEMCP、CP_SYMBOL、CP_THREAD_ACP, CP_UTF7 和 CP_UTF8。
-----------------------------------------------------------------
2.MySQL:
格式: db_connect(array([string server [, string username [, string password [, bool new_link [, int client_flags]]]]]));
建立一个到 MySQL 服务器的连接。当没有提供可选参数时使用以下默认值:server = 'localhost:3306',username = 服务器进程所有者的用户名,password = 空密码。
server 参数可以包括端口号。例如 "hostname:port" 或者是到本地套接字的路径,例如本机上的 ":/path/to/socket"。
注: 无论指定 "localhost" 或者 "localhost:port" 作为 server,MySQL 客户端库将覆盖之并尝试连接到本地套接字(Windows 中的名字管道)。如果希望使用 TCP/IP 连接,用 "127.0.0.1" 替代 "localhost"。如果 MySQL 客户端库试图连接到错误的本地套接字,则应该在 PHP 配置中将 mysql.default_host 设为正确的路径并使 server 字段为空。
":port" 的支持是 PHP 3.0B4 起加入的。
":/path/to/socket" 的支持是 PHP 3.0.10 起加入的。
-----------------------------------------------------------------
3.MS SQL:
格式: db_connect(array([string servername [, string username [, string password]]]));
servername : 服务器名.
username: 用户名.
password: 密码.
-----------------------------------------------------------------
*/
function db_connect($_args = array()){
$this->args = $_args;
switch($this->dbClass){
case "access":
$this->access_db_connect();
return $this->conn;
break;
case "mysql":
$this->mysql_db_connect();
return $this->conn;
break;
case "mssql":
$this->mssql_db_connect();
return $this->conn;
break;
default:
return false;
break;
}//end.switch;
}//end.db_connect;
//2.1.连接Access
function access_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @new COM("ADODB.Connection");
break;
case 1:
$this->conn = @new COM("ADODB.Connection",$this->args[0]);
break;
case 2:
$this->conn = @new COM("ADODB.Connection",$this->args[0],$this->args[1]);
break;
default:
$this->conn = false;
break;
}//end.switch;
}//end.access_db_connect;
//2.2.1.连接MySQL
function mysql_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @mysql_connect();
break;
case 1:
$this->conn = @mysql_connect($this->args[0]);
break;
case 2:
$this->conn = @mysql_connect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2]);
break;
case 4:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2],$this->args[3]);
break;
case 5:
$this->conn = @mysql_connect($this->args[0],$this->args[1],$this->args[2],$this->args[3],$this->args[4]);
break;
default:
return false;
break;
}
}//end.mysql_db_connect;
//2.2.2.连接MySQL
function mysql_db_pconnect(){
switch(count($this->args)){
case 0:
$this->conn = @mysql_pconnect();
break;
case 1:
$this->conn = @mysql_pconnect($this->args[0]);
break;
case 2:
$this->conn = @mysql_pconnect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mysql_pconnect($this->args[0],$this->args[1],$this->args[2]);
break;
default:
$this->conn = false;
break;
}
}//end.mysql_db_connect;
//2.3.连接MS SQL
function mssql_db_connect(){
switch(count($this->args)){
case 0:
$this->conn = @mssql_connect();
break;
case 1:
$this->conn = @mssql_connect($this->args[0]);
break;
case 2:
$this->conn = @mssql_connect($this->args[0],$this->args[1]);
break;
case 3:
$this->conn = @mssql_connect($this->args[0],$this->args[1],$this->args[2]);
break;
default:
$this->conn = false;
break;
}
}//end.mssql_db_connect;
//3.选择数据库 ==================================================
//3.1.选择数据库
/*
调用方法:
1.access:
格式: select_db(array(string dbName [, string UserID [, string Password]]))
dbName : 数据库名(相对路径+数据库名)
UserID : 用户ID
Password : 密码
-----------------------------------------------------------------
2.MySQL:
格式: select_db(array(string database_name [, resource link_identifier]))
database_name : 数据库名
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: select_db(array(string database_name [, resource link_identifier]))
database_name : 数据库名
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function select_db($_args = array()){
$this->args = $_args;
switch($this->dbClass){
case "access":
$this->db_access_select_db();
return $this->conn;
break;
case "mysql":
return $this->db_mysql_select_db();
break;
case "mssql":
return $this->db_mssql_select_db();
break;
default:
break;
}//end.switch;
}//end.select_db;
//3.2.access选择数据库
function db_access_select_db(){
switch(count($this->args)){
case 1:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";";
$this->conn->open($dsn);
break;
case 2:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";UID=".$this->args[1].";";
$this->conn->open($dsn);
break;
case 3:
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath($this->args[0]).";UID=".$this->args[1].";Pwd=".$this->args[2].";";
$this->conn->open($dsn);
break;
default:
return false;
break;
}//end.switch;
}//end.
//3.3.MySQL选择数据库
function db_mysql_select_db(){
if(isset($this->args[1])) return @mysql_select_db($this->args[0],$this->args[1]);
else return @mysql_select_db($this->args[0]);
}//end.db_mysql_select_db;
//3.4.MsSQL选择数据库
function db_mssql_select_db($_args = array()){
if(isset($this->args[1])) return @mssql_select_db($this->args[0],$this->args[1]);
else return @mssql_select_db($this->args[0]);
}//end.db_mysql_select_db;
#38
//4.执行SQL语句 =================================================
//4.1.执行返回结果集的SQL语句
/*
调用方法:
1.access:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
2.MySQL:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function open($_sqlstr,$_conn = null){
$this->sqlstr = $_sqlstr;
if($this->debug) echo "<br>SQL: " . $_sqlstr;
$this->bof = true;
$this->eof = false;
$this->accessFetch = true;
switch($this->dbClass){
case "access":
return $this->open_access($_sqlstr);
break;
case "mysql":
return $this->open_mysql($_sqlstr,$_conn);
break;
case "mssql":
return $this->open_mssql($_sqlstr,$_conn);
break;
default:
$this->eof = true;
return false;
break;
}//end.switch;
}//end.open;
//4.1.1.access.执行返回结果集的SQL语句
function open_access($_sqlstr){
//echo "SQL:" . $_sqlstr . "<br>";
return $this->conn->Execute($_sqlstr);
}//end.open_access;
//4.1.2.MySQL.执行返回结果集的SQL语句
function open_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
return @mysql_query($_sqlstr,$_conn);
else
return @mysql_query($_sqlstr);
}//end.open_mysql;
//4.1.3.MS SQL.执行返回结果集的SQL语句
function open_mssql(&$_sqlstr,&$_conn){
if(isset($_conn))
return @mysql_query($_sqlstr,$_conn);
else
return @mysql_query($_sqlstr);
}//end.open_mssql;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//4.2.执行不返回结果集的SQL语句
/*
调用方法:
1.access:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
2.MySQL:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function execute($_sqlstr,$_conn = null){
$this->sqlstr = $_sqlstr;
if($this->debug) echo "<br>SQL: " . $_sqlstr;
$this->bof = false;
$this->eof = false;
switch($this->dbClass){
case "access":
$this->exec_access($_sqlstr);
break;
case "mysql":
$this->exec_mysql($_sqlstr,$_conn);
break;
//case "mysql_db":
// $this->exec_db_mysql($_sqlstr,$_conn);
case "mssql":
$this->exec_mssql($_sqlstr,$_conn);
break;
default:
break;
}//end.switch;
}//end.execute;
//4.2.1.access.执行不返回结果集的SQL语句
function exec_access(&$_sqlstr){
$this->conn->Execute($_sqlstr);
}//end.exec_access;
//4.2.2.1.MySQL.执行不返回结果集的SQL语句
function exec_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
@mysql_query($_sqlstr,$_conn);
else
@mysql_query($_sqlstr);
}//end.exec_mysql;
//4.2.2.2.MySQL.执行不返回结果集的SQL语句
/*
function exec_db_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
$info = @mysql_query($this->args[0],$this->args[1],$this->args[2]);
else
$info = @mysql_query($this->args[0],$this->args[1]);
}//end.exec_mysql;
*/
//4.2.3.MS SQL.执行不返回结果集的SQL语句
function exec_mssql(&$_sqlstr,&$_conn){
if(isset($_conn))
@mysql_query($_sqlstr,$_conn);
else
@mysql_query($_sqlstr);
}//end.exec_mssql;
//4.3.执行不返回结果集的SQL语句(简写)
function exec($_args = array()){
$this->execute($_args);
}//end.exec;
//4.1.执行返回结果集的SQL语句
/*
调用方法:
1.access:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
2.MySQL:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: open(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function open($_sqlstr,$_conn = null){
$this->sqlstr = $_sqlstr;
if($this->debug) echo "<br>SQL: " . $_sqlstr;
$this->bof = true;
$this->eof = false;
$this->accessFetch = true;
switch($this->dbClass){
case "access":
return $this->open_access($_sqlstr);
break;
case "mysql":
return $this->open_mysql($_sqlstr,$_conn);
break;
case "mssql":
return $this->open_mssql($_sqlstr,$_conn);
break;
default:
$this->eof = true;
return false;
break;
}//end.switch;
}//end.open;
//4.1.1.access.执行返回结果集的SQL语句
function open_access($_sqlstr){
//echo "SQL:" . $_sqlstr . "<br>";
return $this->conn->Execute($_sqlstr);
}//end.open_access;
//4.1.2.MySQL.执行返回结果集的SQL语句
function open_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
return @mysql_query($_sqlstr,$_conn);
else
return @mysql_query($_sqlstr);
}//end.open_mysql;
//4.1.3.MS SQL.执行返回结果集的SQL语句
function open_mssql(&$_sqlstr,&$_conn){
if(isset($_conn))
return @mysql_query($_sqlstr,$_conn);
else
return @mysql_query($_sqlstr);
}//end.open_mssql;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//4.2.执行不返回结果集的SQL语句
/*
调用方法:
1.access:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
2.MySQL:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
-----------------------------------------------------------------
3.MS SQL:
格式: execute(string sqlstr[, resource link_identifier])
sqlstr : SQL语句.
link_identifier : 连接标识符(conn)
如果没有指定link_identifier(连接标识符),则使用上一个打开的连接。
*/
function execute($_sqlstr,$_conn = null){
$this->sqlstr = $_sqlstr;
if($this->debug) echo "<br>SQL: " . $_sqlstr;
$this->bof = false;
$this->eof = false;
switch($this->dbClass){
case "access":
$this->exec_access($_sqlstr);
break;
case "mysql":
$this->exec_mysql($_sqlstr,$_conn);
break;
//case "mysql_db":
// $this->exec_db_mysql($_sqlstr,$_conn);
case "mssql":
$this->exec_mssql($_sqlstr,$_conn);
break;
default:
break;
}//end.switch;
}//end.execute;
//4.2.1.access.执行不返回结果集的SQL语句
function exec_access(&$_sqlstr){
$this->conn->Execute($_sqlstr);
}//end.exec_access;
//4.2.2.1.MySQL.执行不返回结果集的SQL语句
function exec_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
@mysql_query($_sqlstr,$_conn);
else
@mysql_query($_sqlstr);
}//end.exec_mysql;
//4.2.2.2.MySQL.执行不返回结果集的SQL语句
/*
function exec_db_mysql(&$_sqlstr,&$_conn){
if(isset($_conn))
$info = @mysql_query($this->args[0],$this->args[1],$this->args[2]);
else
$info = @mysql_query($this->args[0],$this->args[1]);
}//end.exec_mysql;
*/
//4.2.3.MS SQL.执行不返回结果集的SQL语句
function exec_mssql(&$_sqlstr,&$_conn){
if(isset($_conn))
@mysql_query($_sqlstr,$_conn);
else
@mysql_query($_sqlstr);
}//end.exec_mssql;
//4.3.执行不返回结果集的SQL语句(简写)
function exec($_args = array()){
$this->execute($_args);
}//end.exec;
#39
系统不让再发了,换个用户再发:
//5.显示结果集 ==================================================
//5.1.返回row式结果集.
/*
调用格式:
语法格式: fetch_row(resource result);
result: 是查询结果集.
fetch_row()是从和指定的结果标识关联的结果集中取得一行数据并作为数组返回。
适用于access,mysql,mssql,odbc.
例5.1.:
require("class/mydbs.class.v2.php");
$acs = new mydbs("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs/dbs77.mdb"));
$rs = $acs->open(array("select * from tmp01"));
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
*/
function &fetch_row(&$_result){
switch($this->dbClass){
case "access":
if($this->accessFetch){
$this->db_access_dataSet_rows($_result);
$this->accessFetch = false;
if(isset($this->dataSet[0])) return $this->dataSet[0];
else return false;
}else{
if(!$this->eof){
return $this->access_fetch_row();
}else{
echo ".end";
$this->accessFetch = true;
$this->bof = true;
$this->eof = false;
return false;
}//end.if;
}//end.if;
break;
case "mysql":
return mysql_fetch_row($_result);
break;
case "mssql":
return mssql_fetch_row($_result);
break;
default:
return false;
break;
}//end.switch;
}//end.&fetch_row;
//5.1.1.将access结果集存入数组中
function db_access_dataSet_rows(&$_rs){
//echo ".run3.";
$num_columns = $_rs->Fields->Count();
for ($i=0; $i < $num_columns; $i++)
$fld[$i] = $_rs->Fields($i);
$count = 0;
while (!$_rs->EOF)
{
for ($i=0; $i < $num_columns; $i++) {
$this->dataSet[$count][$i] = $fld[$i]->value;
//echo ":".$fld[$i]->value ;
}
$count++; //count 自增
$_rs->MoveNext();
}//end.while;
$_rs->Close();
$_rs->Release();
}//end.db_access_dataSet_rows;
//5.1.2.返回access的row式结果集
function access_fetch_row(){
if(isset($this->dataSet[$this->rowcount])){
$this->bof = false;
return $this->dataSet[$this->rowcount++];
}
else{
$this->eof = true;
return false;
}//end.if;
}//end.access_fetch_row;
//5.2.返回Array式结果集 +++++++++++++++++++++++++++++++++++++++++
/*
语法格式:
fetch_array(resource result [, int result_type])
返回根据从结果集取得的行生成的数组,如果没有更多行则返回 FALSE。
fetch_array() 是 fetch_row() 的扩展版本。除了将数据以数字索引方式储存在数组中之外,还可以将数据作为关联索引储存,用字段名作为键名。
fetch_array() 中可选的第二个参数 result_type 是一个常量,可以接受以下值:MYSQL_ASSOC,MYSQL_NUM 和 MYSQL_BOTH。本特性是 mydbs V2.0 beta 1.0.1s 起新加的。本参数的默认值是 MYSQL_BOTH。
说明: 如何使用的是Access数据,同不支持第二个参数.
例5.2.(有些部分参见例5.1.):
$rs = $acs->open(array("select * from tmp01"));
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
*/
function fetch_array(&$_result , $result_type=MYSQL_BOTH){
switch($this->dbClass){
case "access":
if($this->accessFetch){
$this->db_access_dataSet_Array($_result);
$this->accessFetch = false;
if(isset($this->dataSet[0])) return $this->dataSet[0];
else return false;
}else{
if(!$this->eof){
return $this->access_fetch_Array();
}else{
$this->accessFetch = true;
$this->bof = true;
$this->eof = false;
return false;
}//end.if;
}//end.if;
break;
case "mysql":
return mysql_fetch_array($_result,$result_type);
break;
case "mssql":
return mssql_fetch_array($_result,$result_type);
break;
default:
return false;
break;
}//end.switch;
}//end.fetch_array;
//5.2.1.将access结果集存入数组中
function db_access_dataSet_Array(&$_rs){
$num_columns = $_rs->Fields->Count();
for ($i=0; $i < $num_columns; $i++)
$fld[$i] = $_rs->Fields($i);
$count = 0;
while (!$_rs->EOF)
{
for ($i=0; $i < $num_columns; $i++)
$this->dataSet[$count][$fld[$i]->name] = $fld[$i]->value;
$count++; //count 自增
$_rs->MoveNext();
}//end.while;
$_rs->Close();
$_rs->Release();
}//end.db_access_dataSet_Array;
//5.2.2.返回access的array式结果集
function access_fetch_array(){
if(isset($this->dataSet[$this->rowcount])){
$this->bof = false;
return $this->dataSet[$this->rowcount++];
}
else{
$this->eof = true;
return false;
}//end.if;
}//end.access_fetch_array;
//5.3.返回结果集行数 ++++++++++++++++++++++++++++++++++++++++++++
//5.显示结果集 ==================================================
//5.1.返回row式结果集.
/*
调用格式:
语法格式: fetch_row(resource result);
result: 是查询结果集.
fetch_row()是从和指定的结果标识关联的结果集中取得一行数据并作为数组返回。
适用于access,mysql,mssql,odbc.
例5.1.:
require("class/mydbs.class.v2.php");
$acs = new mydbs("access");
$conn = $acs->db_connect();
$db = $acs->select_db(array("dbs/dbs77.mdb"));
$rs = $acs->open(array("select * from tmp01"));
echo "<table>";
while($r = $acs->fetch_row($rs)){
echo "<tr><td>".$r[0]."</td><td>".$r[1]."</td></tr>";
}
*/
function &fetch_row(&$_result){
switch($this->dbClass){
case "access":
if($this->accessFetch){
$this->db_access_dataSet_rows($_result);
$this->accessFetch = false;
if(isset($this->dataSet[0])) return $this->dataSet[0];
else return false;
}else{
if(!$this->eof){
return $this->access_fetch_row();
}else{
echo ".end";
$this->accessFetch = true;
$this->bof = true;
$this->eof = false;
return false;
}//end.if;
}//end.if;
break;
case "mysql":
return mysql_fetch_row($_result);
break;
case "mssql":
return mssql_fetch_row($_result);
break;
default:
return false;
break;
}//end.switch;
}//end.&fetch_row;
//5.1.1.将access结果集存入数组中
function db_access_dataSet_rows(&$_rs){
//echo ".run3.";
$num_columns = $_rs->Fields->Count();
for ($i=0; $i < $num_columns; $i++)
$fld[$i] = $_rs->Fields($i);
$count = 0;
while (!$_rs->EOF)
{
for ($i=0; $i < $num_columns; $i++) {
$this->dataSet[$count][$i] = $fld[$i]->value;
//echo ":".$fld[$i]->value ;
}
$count++; //count 自增
$_rs->MoveNext();
}//end.while;
$_rs->Close();
$_rs->Release();
}//end.db_access_dataSet_rows;
//5.1.2.返回access的row式结果集
function access_fetch_row(){
if(isset($this->dataSet[$this->rowcount])){
$this->bof = false;
return $this->dataSet[$this->rowcount++];
}
else{
$this->eof = true;
return false;
}//end.if;
}//end.access_fetch_row;
//5.2.返回Array式结果集 +++++++++++++++++++++++++++++++++++++++++
/*
语法格式:
fetch_array(resource result [, int result_type])
返回根据从结果集取得的行生成的数组,如果没有更多行则返回 FALSE。
fetch_array() 是 fetch_row() 的扩展版本。除了将数据以数字索引方式储存在数组中之外,还可以将数据作为关联索引储存,用字段名作为键名。
fetch_array() 中可选的第二个参数 result_type 是一个常量,可以接受以下值:MYSQL_ASSOC,MYSQL_NUM 和 MYSQL_BOTH。本特性是 mydbs V2.0 beta 1.0.1s 起新加的。本参数的默认值是 MYSQL_BOTH。
说明: 如何使用的是Access数据,同不支持第二个参数.
例5.2.(有些部分参见例5.1.):
$rs = $acs->open(array("select * from tmp01"));
echo "<table>";
while($r = $acs->fetch_array($rs)){
echo "<tr><td>".$r["id"]."</td><td>".$r["name"]."</td></tr>";
}
*/
function fetch_array(&$_result , $result_type=MYSQL_BOTH){
switch($this->dbClass){
case "access":
if($this->accessFetch){
$this->db_access_dataSet_Array($_result);
$this->accessFetch = false;
if(isset($this->dataSet[0])) return $this->dataSet[0];
else return false;
}else{
if(!$this->eof){
return $this->access_fetch_Array();
}else{
$this->accessFetch = true;
$this->bof = true;
$this->eof = false;
return false;
}//end.if;
}//end.if;
break;
case "mysql":
return mysql_fetch_array($_result,$result_type);
break;
case "mssql":
return mssql_fetch_array($_result,$result_type);
break;
default:
return false;
break;
}//end.switch;
}//end.fetch_array;
//5.2.1.将access结果集存入数组中
function db_access_dataSet_Array(&$_rs){
$num_columns = $_rs->Fields->Count();
for ($i=0; $i < $num_columns; $i++)
$fld[$i] = $_rs->Fields($i);
$count = 0;
while (!$_rs->EOF)
{
for ($i=0; $i < $num_columns; $i++)
$this->dataSet[$count][$fld[$i]->name] = $fld[$i]->value;
$count++; //count 自增
$_rs->MoveNext();
}//end.while;
$_rs->Close();
$_rs->Release();
}//end.db_access_dataSet_Array;
//5.2.2.返回access的array式结果集
function access_fetch_array(){
if(isset($this->dataSet[$this->rowcount])){
$this->bof = false;
return $this->dataSet[$this->rowcount++];
}
else{
$this->eof = true;
return false;
}//end.if;
}//end.access_fetch_array;
//5.3.返回结果集行数 ++++++++++++++++++++++++++++++++++++++++++++
#40
//6.查询分页 ====================================================
//6.1.设置查询分页 ----------------------------------------------
//6.1.1.设置每页行数
function &setPage_Linage($_Linage = 0){
$this->Linage = $_Linage;
if($_Linage>0) $this->count_MaxPage();
else $this->MaxPage = 1;
}//end.setPage_Linage;
//6.1.2.计算总页数 ----------------------------------------------
function &count_MaxPage(){
$sqltmp = $this->sqlstr;
$sql = preg_replace(array ("'select.*?from'si","'order by.*'"), array ("select count(*), count(*)/$this->Linage from "," "), $sqltmp);
$rs = $this->open($sql);
while($r = $this->fetch_row($rs)){
$this->MaxCount = $r[0];
$this->MaxPage = $r[1];
}//end.while;
$this->MaxPage = ceil($this->MaxPage); //存储页数
$this->sqlstr = $sqltmp ;
}//end.count_MaxPage;
//6.1.3.设置当前页号 --------------------------------------------
function &setPage_CurrentPage($_CurrentPage = 1){
if($_CurrentPage<=1){
$this->CurrentPage = 1;
}else{
if($_CurrentPage>$this->MaxPage) $this->CurrentPage = $this->MaxPage;
else $this->CurrentPage = $_CurrentPage;
}//end.if;
//return $this->CurrentPage;
}//end.setPage_CurrentPage;
//6.1.4.计算偏移量 ----------------------------------------------
function &count_Offset($_CurrentPage = 0, $_Linage = 0){
/*if($_Linage>0){
$this->Linage = $_Linage;
$this->count_MaxPage(); //修改后要重新计算总页数.
}else{
if(($this->MaxPage<=0)&&($this->MaxCount>0)) //如果尚未计算总页数,则计算总页数
$this->count_MaxPage(); //重新计算总页数
}//end.if;
if($_CurrentPage<>0) $this->CurrentPage = $_CurrentPage;
else $this->CurrentPage = 0;*/
$this->offset = $_Linage * ($_CurrentPage - 1);
//return $this->offset;
}//end.count_Offset;
function &SelectLimit($_sqlstr=null,$_CurrentPage=0,$_Linage=0,$_style=0){
$this->sqlstr = $_sqlstr;
//$this->count_MaxPage($_sqlstr);
$this->count_Offset($_CurrentPage,$_Linage); //计算偏移量
if( $_Linage > 0 ) $this->setPage_Linage($_Linage);
if( $_CurrentPage > 0 ) $this->CurrentPage = $this->setPage_CurrentPage($_CurrentPage);
switch($this->dbClass){
case "access":
return $this->AccessSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
case "mysql":
return $this->MySQLSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
case "mssql":
return $this->MSSQLSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
default:
return false;
break;
}//end.switch;
}//end.&SelectLimit;
//6.2.1.Access分页查询
function &AccessSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
$sqltmp = preg_replace("'^select'","select top $_Linage",$sqltmp);
if($this->offset>0)
$sqlClause = preg_replace("'^select.*from'","id <> all(select top $this->offset id from",$sqltmp).")";
if($this->offset>0){
$sqltmp = preg_replace("'where '" ,"where ($sqlClause) and ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp = preg_replace("'order by '"," where $sqlClause order by ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp .= " where $sqlClause ";
}
return $this->open($sqltmp);
/* while(!$rs->EOF){
$a1 = $rs->fields("id");
$a2 = $rs->fields("name");
echo "<br>*.".$a1->value." - ".$a2->value;
$rs->MoveNext();
}
*/
}//end.&AccessSelectLimit;
//6.2.2.MySQL分页查询
function &MySqlSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
if(strspn("LIMIT",$sqltmp)==0){
$sqltmp .= " LIMIT $this->offset,$_Linage)";
}//end.if;
return $this->open($sqltmp);
}//end.&MySqlSelectLimit;
//6.2.3.MS SQL分页查询
function &MSSqlSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
$sqltmp = preg_replace("'^select'","select top $_Linage",$sqltmp);
if($this->offset>0)
$sqlClause = preg_replace("'^select.*from'","id <> all(select top $this->offset id from",$sqltmp).")";
if($this->offset>0){
$sqltmp = preg_replace("'where '" ,"where ($sqlClause) and ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp = preg_replace("'order by '"," where $sqlClause order by ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp .= " where $sqlClause ";
}
return $this->open($sqltmp);
}//end.&MSSqlSelectLimit;
//6.1.设置查询分页 ----------------------------------------------
//6.1.1.设置每页行数
function &setPage_Linage($_Linage = 0){
$this->Linage = $_Linage;
if($_Linage>0) $this->count_MaxPage();
else $this->MaxPage = 1;
}//end.setPage_Linage;
//6.1.2.计算总页数 ----------------------------------------------
function &count_MaxPage(){
$sqltmp = $this->sqlstr;
$sql = preg_replace(array ("'select.*?from'si","'order by.*'"), array ("select count(*), count(*)/$this->Linage from "," "), $sqltmp);
$rs = $this->open($sql);
while($r = $this->fetch_row($rs)){
$this->MaxCount = $r[0];
$this->MaxPage = $r[1];
}//end.while;
$this->MaxPage = ceil($this->MaxPage); //存储页数
$this->sqlstr = $sqltmp ;
}//end.count_MaxPage;
//6.1.3.设置当前页号 --------------------------------------------
function &setPage_CurrentPage($_CurrentPage = 1){
if($_CurrentPage<=1){
$this->CurrentPage = 1;
}else{
if($_CurrentPage>$this->MaxPage) $this->CurrentPage = $this->MaxPage;
else $this->CurrentPage = $_CurrentPage;
}//end.if;
//return $this->CurrentPage;
}//end.setPage_CurrentPage;
//6.1.4.计算偏移量 ----------------------------------------------
function &count_Offset($_CurrentPage = 0, $_Linage = 0){
/*if($_Linage>0){
$this->Linage = $_Linage;
$this->count_MaxPage(); //修改后要重新计算总页数.
}else{
if(($this->MaxPage<=0)&&($this->MaxCount>0)) //如果尚未计算总页数,则计算总页数
$this->count_MaxPage(); //重新计算总页数
}//end.if;
if($_CurrentPage<>0) $this->CurrentPage = $_CurrentPage;
else $this->CurrentPage = 0;*/
$this->offset = $_Linage * ($_CurrentPage - 1);
//return $this->offset;
}//end.count_Offset;
function &SelectLimit($_sqlstr=null,$_CurrentPage=0,$_Linage=0,$_style=0){
$this->sqlstr = $_sqlstr;
//$this->count_MaxPage($_sqlstr);
$this->count_Offset($_CurrentPage,$_Linage); //计算偏移量
if( $_Linage > 0 ) $this->setPage_Linage($_Linage);
if( $_CurrentPage > 0 ) $this->CurrentPage = $this->setPage_CurrentPage($_CurrentPage);
switch($this->dbClass){
case "access":
return $this->AccessSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
case "mysql":
return $this->MySQLSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
case "mssql":
return $this->MSSQLSelectLimit($this->sqlstr,$_CurrentPage,$_Linage,$_style);
break;
default:
return false;
break;
}//end.switch;
}//end.&SelectLimit;
//6.2.1.Access分页查询
function &AccessSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
$sqltmp = preg_replace("'^select'","select top $_Linage",$sqltmp);
if($this->offset>0)
$sqlClause = preg_replace("'^select.*from'","id <> all(select top $this->offset id from",$sqltmp).")";
if($this->offset>0){
$sqltmp = preg_replace("'where '" ,"where ($sqlClause) and ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp = preg_replace("'order by '"," where $sqlClause order by ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp .= " where $sqlClause ";
}
return $this->open($sqltmp);
/* while(!$rs->EOF){
$a1 = $rs->fields("id");
$a2 = $rs->fields("name");
echo "<br>*.".$a1->value." - ".$a2->value;
$rs->MoveNext();
}
*/
}//end.&AccessSelectLimit;
//6.2.2.MySQL分页查询
function &MySqlSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
if(strspn("LIMIT",$sqltmp)==0){
$sqltmp .= " LIMIT $this->offset,$_Linage)";
}//end.if;
return $this->open($sqltmp);
}//end.&MySqlSelectLimit;
//6.2.3.MS SQL分页查询
function &MSSqlSelectLimit(&$_sqlstr,&$_CurrentPage,&$_Linage,&$_style){
$sqltmp = $_sqlstr;
$this->count_Offset($_CurrentPage,$_Linage);
$sqltmp = preg_replace("'^select'","select top $_Linage",$sqltmp);
if($this->offset>0)
$sqlClause = preg_replace("'^select.*from'","id <> all(select top $this->offset id from",$sqltmp).")";
if($this->offset>0){
$sqltmp = preg_replace("'where '" ,"where ($sqlClause) and ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp = preg_replace("'order by '"," where $sqlClause order by ",$sqltmp);
if(strspn("where",$sqltmp)==0)
$sqltmp .= " where $sqlClause ";
}
return $this->open($sqltmp);
}//end.&MSSqlSelectLimit;
#41
//7.完成较复杂的插入语句 ========================================
function &InsertAdd($_sql1,$_sql2,$_class="char",$_TableName=""){
if(($_sql1!="")&&($_sql2=="")){
return false;
}else{
switch($_class){
case "char":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "int":
$this->sql1 .= $_sql1.",";
$this->sql2 .= $_sql2.",";
break;
case "text":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "date":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "datetime":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "time":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "$":
$this->sql1 .= $_sql1.",";
$this->sql2 .= $_sql2.",";
break;
case "exec":
if($_TableName <> ""){
$_sql1 = preg_replace("',$'","",$this->sql1);
$_sql2 = preg_replace("',$'","",$this->sql2);
$this->sql1 = "insert into ". $_TableName ."(" . $_sql1 . ")";
$this->sql2 = " values(" . $_sql2 . ")";
//echo "=+".$this->sql1 . $this->sql2 ."+=";
$this->execute($this->sql1 . $this->sql2);
return true;
}
break;
default:
return false;
break;
}//end.switch;
}//end.if;
}//end.&insert;
function &InsertAdd($_sql1,$_sql2,$_class="char",$_TableName=""){
if(($_sql1!="")&&($_sql2=="")){
return false;
}else{
switch($_class){
case "char":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "int":
$this->sql1 .= $_sql1.",";
$this->sql2 .= $_sql2.",";
break;
case "text":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "date":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "datetime":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "time":
$this->sql1 .= $_sql1.",";
$this->sql2 .= "'".$_sql2."',";
break;
case "$":
$this->sql1 .= $_sql1.",";
$this->sql2 .= $_sql2.",";
break;
case "exec":
if($_TableName <> ""){
$_sql1 = preg_replace("',$'","",$this->sql1);
$_sql2 = preg_replace("',$'","",$this->sql2);
$this->sql1 = "insert into ". $_TableName ."(" . $_sql1 . ")";
$this->sql2 = " values(" . $_sql2 . ")";
//echo "=+".$this->sql1 . $this->sql2 ."+=";
$this->execute($this->sql1 . $this->sql2);
return true;
}
break;
default:
return false;
break;
}//end.switch;
}//end.if;
}//end.&insert;
#42
///20.session功能
//20.1.创建session功能表
function CreateLoginInfoTable(){
switch($this->dbClass){
case "access":
$sql = "create table SessionLoginInfo(userid varchar(50) not null primary key, sessionid varchar(50), IP char(20) , logintime datetime, mm int)";
break;
case "mysql":
$sql = "create table SessionLoginInfo(userid varchar(50) not null, sessionid varchar(50) not null,IP char(20),logintime datetime,mm bigint(20),primary key (userid))";
break;
case "mssql":
$sql = "create table SessionLoginInfo(userid varchar(50) not null primary key, sessionid varchar(50), IP char(20) , logintime datetime, mm bigint)";
break;
default:
$sql = "";
break;
}//end.switch;
$this->execute($sql);
}//end.CreateLoginInfoTable;
//20.2.写入登录者
function &setSessionLoginInfo($_userid,$_sessionid,$_ip,$_datetime,$_mm){
if($row=$this->getSessionLoginInfo($_userid)){
$sessionid = $row["sessionid"];
$mm = $row["mm"];
$ip = $row["IP"];
if($sessionid == $_sessionid){
$_datetime = date("Y-m-d H:i");
$_mm = (int)(date("U")/60);
$sql = "update SessionLoginInfo set mm = $_mm where userid = '$_userid'";
$this->execute($sql);
return true;
}else{
return false;
}//end.if;
}else{
$_mm = (int)($_mm/60);
$sql = "insert into SessionLoginInfo(userid,sessionid,ip,logintime,mm) values('$_userid','$_sessionid','$_ip','$_datetime',$_mm)";
$this->execute($sql);
return true;
}//end.if;
}//end.&setSessionLoginInfo;
//20.3.读出登录者
function &getSessionLoginInfo($_userid){
$sql = "select * from SessionLoginInfo where userid = '$_userid'";
$rs = $this->open($sql);
if($row = $this->fetch_array($rs)) return $row;
else return false;
}//end.&getSessionLoginInfo;
//20.4.刷新登录信息库
function &FlashSessionLoginInfo(){
$mm = (int)(date("U")/60);
$sql = "delete from SessionLoginInfo where $mm - mm > $this->SessionTime";
$this->execute($sql);
}//end.&FlashSessionLoginInf;
//20.5.注销登录信息
function &LogoutSessionLoginInfo($_userid){
$sql = "delete from SessionLoginInfo where userid = '$_userid'";
$this->execute($sql);
}//end.
}//end.class.mydbs.
?>
//20.1.创建session功能表
function CreateLoginInfoTable(){
switch($this->dbClass){
case "access":
$sql = "create table SessionLoginInfo(userid varchar(50) not null primary key, sessionid varchar(50), IP char(20) , logintime datetime, mm int)";
break;
case "mysql":
$sql = "create table SessionLoginInfo(userid varchar(50) not null, sessionid varchar(50) not null,IP char(20),logintime datetime,mm bigint(20),primary key (userid))";
break;
case "mssql":
$sql = "create table SessionLoginInfo(userid varchar(50) not null primary key, sessionid varchar(50), IP char(20) , logintime datetime, mm bigint)";
break;
default:
$sql = "";
break;
}//end.switch;
$this->execute($sql);
}//end.CreateLoginInfoTable;
//20.2.写入登录者
function &setSessionLoginInfo($_userid,$_sessionid,$_ip,$_datetime,$_mm){
if($row=$this->getSessionLoginInfo($_userid)){
$sessionid = $row["sessionid"];
$mm = $row["mm"];
$ip = $row["IP"];
if($sessionid == $_sessionid){
$_datetime = date("Y-m-d H:i");
$_mm = (int)(date("U")/60);
$sql = "update SessionLoginInfo set mm = $_mm where userid = '$_userid'";
$this->execute($sql);
return true;
}else{
return false;
}//end.if;
}else{
$_mm = (int)($_mm/60);
$sql = "insert into SessionLoginInfo(userid,sessionid,ip,logintime,mm) values('$_userid','$_sessionid','$_ip','$_datetime',$_mm)";
$this->execute($sql);
return true;
}//end.if;
}//end.&setSessionLoginInfo;
//20.3.读出登录者
function &getSessionLoginInfo($_userid){
$sql = "select * from SessionLoginInfo where userid = '$_userid'";
$rs = $this->open($sql);
if($row = $this->fetch_array($rs)) return $row;
else return false;
}//end.&getSessionLoginInfo;
//20.4.刷新登录信息库
function &FlashSessionLoginInfo(){
$mm = (int)(date("U")/60);
$sql = "delete from SessionLoginInfo where $mm - mm > $this->SessionTime";
$this->execute($sql);
}//end.&FlashSessionLoginInf;
//20.5.注销登录信息
function &LogoutSessionLoginInfo($_userid){
$sql = "delete from SessionLoginInfo where userid = '$_userid'";
$this->execute($sql);
}//end.
}//end.class.mydbs.
?>
#43
过了这么久,有测评么?
#44
我以前也写不过觉得没有成熟的代码好啊!比如phplib
#45
可以拆分成几个类,不同的功能分到不同的类里面
#46
想看看guye99@163.com
#47
你强.............我顶..............
#48
发过来看看呐!
hjmsoalr@163.com
hjmsoalr@163.com
#49
meng.chao@163.com
#50
wind619@126.com 谢谢