Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)归海一刀
published in(发表于) 2014/2/17 7:39:24
php编写的ACCESS处理类_[PHP教程]

php编写的ACCESS处理类_[PHP教程]

在做项目中要用到ACCESS数据库,所以就写了一个ACCESS处理类.函数名跟ADODB类一样.



/*
*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();
}



}

?>

来源:http://blog.csdn.net/liq330





If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759