php编写的ACCESS处理类_PHP教程
教程Tag:暂无Tag,欢迎添加,赚取U币!
推荐:解析基于MVC的轻量级PHP框架做WEB开发已有一年,每次都写重复的东西, 因此,想自己写一下框架,以后开发方便. 本人之前学习asp.NET两年,JSP半年,可是后来因为工作的原故换成PHP.其实很不喜欢PHP的语法.还有PHP的函数名,每回都忘记..还是喜欢C#和JAVA的语法,哈...不过PHP有PHP的优点,不像AS
在做项目中要用到ACCESS数据库,所以就写了一个ACCESS处理类.函数名跟ADODB类一样.
<?php
/*
*ACCESS数据库操作类
*2008-3-26
*LIQUAN
*dsn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".PATH_ROOT."databasedata.mdb";
*conn=new Access();
*conn->Connnect(dsn);
*conn->GetArray("select * from test");
*/
class Access
{
var conn;
var fieldsName;
function Access()
{
}
//connection
function Connect(dsn)
{
this->conn = new COM("ADODB.Connection") or die("Cannot start ADO");
this->conn->Open(dsn);
}
//返回一个
function GetOne(sql)
{
rs = this->conn->Execute(sql);
while (!rs->EOF)
{
value=rs->Fields(0)->value;
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(value))
{
return value;
}
else
{
return "";
}
unset(value);
}
//返回大数组
function GetArray(sql)
{
rs = this->conn->Execute(sql);
num_columns = rs->Fields->Count();
rowcount = 0;
while (!rs->EOF)
{
for (i=0; i < num_columns; i++)
{
fieldName[rowcount][rs->Fields(i)->name]= rs->Fields(i)->value;
}
rowcount++;
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(fieldName))
{
return fieldName;
}
else
{
return "";
}
unset(fieldName);
}
//返回小数组
function GetRow(sql)
{
rs = this->conn->Execute(sql);
num_columns = rs->Fields->Count();
while (!rs->EOF)
{
for (i=0; i < num_columns; i++)
{
fieldName[rs->Fields(i)->name]=rs->Fields(i)->value;
}
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(fieldName))
{
return fieldName;
}
else
{
return "";
}
unset(fieldName);
}
//execute SQL
function Execute(sql)
{
if(this->conn->Execute(sql))
{
return true;
}
else
{
return false;
}
}
function Close()
{
this->conn->Close();
}
function __destruct()
{
// this->conn->Close();
}
}
?>
/*
*ACCESS数据库操作类
*2008-3-26
*LIQUAN
*dsn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".PATH_ROOT."databasedata.mdb";
*conn=new Access();
*conn->Connnect(dsn);
*conn->GetArray("select * from test");
*/
class Access
{
var conn;
var fieldsName;
function Access()
{
}
//connection
function Connect(dsn)
{
this->conn = new COM("ADODB.Connection") or die("Cannot start ADO");
this->conn->Open(dsn);
}
//返回一个
function GetOne(sql)
{
rs = this->conn->Execute(sql);
while (!rs->EOF)
{
value=rs->Fields(0)->value;
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(value))
{
return value;
}
else
{
return "";
}
unset(value);
}
//返回大数组
function GetArray(sql)
{
rs = this->conn->Execute(sql);
num_columns = rs->Fields->Count();
rowcount = 0;
while (!rs->EOF)
{
for (i=0; i < num_columns; i++)
{
fieldName[rowcount][rs->Fields(i)->name]= rs->Fields(i)->value;
}
rowcount++;
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(fieldName))
{
return fieldName;
}
else
{
return "";
}
unset(fieldName);
}
//返回小数组
function GetRow(sql)
{
rs = this->conn->Execute(sql);
num_columns = rs->Fields->Count();
while (!rs->EOF)
{
for (i=0; i < num_columns; i++)
{
fieldName[rs->Fields(i)->name]=rs->Fields(i)->value;
}
rs->MoveNext();
}
rs->Close();
rs=null;
if(!empty(fieldName))
{
return fieldName;
}
else
{
return "";
}
unset(fieldName);
}
//execute SQL
function Execute(sql)
{
if(this->conn->Execute(sql))
{
return true;
}
else
{
return false;
}
}
function Close()
{
this->conn->Close();
}
function __destruct()
{
// this->conn->Close();
}
}
?>
分享:php如何实现报表类原创内容....实现曲线图,饼图,柱形图. 转贴请注明出处, http://blog.csdn.net/liq330 效果图: 原代码如下: ?php class ImageReport { var Image;//图片对像 var ImageName;//报表名称 var ImageType;//报表类型 var ImageWidth;//图片宽 var ImageHeight;//
相关PHP教程:
- 相关链接:
- 教程说明:
PHP教程-php编写的ACCESS处理类。