php操作access数据库类代码
2008-08-24 21:27
453 查看
class.php文件:
[php]
<?php
class Access//Access数据库操作类
{
var $databasepath,$constr,$dbusername,$dbpassword,$link;//类的属性
function Access($databasepath,$dbusername,$dbpassword)//构造函数
{
$this->databasepath=$databasepath;
$this->username=$dbusername;
$this->password=$dbpassword;
$this->connect();
}
function connect()//数据库连接函数
{
$this->constr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath($this->databasepath);
$this->link=odbc_connect($this->constr,$this->username,$this->password,SQL_CUR_USE_ODBC);
return $this->link;
//if($this->link) echo "恭喜你,数据库连接成功!";
//else echo "数据库连接失败!";
}
function query($sql)//送一个查询字符串到数据库中
{
return @odbc_exec($this->link,$sql);
}
function first_array($sql)//从access数据库中返回一个数组
{
return @odbc_fetch_array($this->query($sql));
}
function fetch_row($query)//返回记录中的一行
{
return odbc_fetch_row($query);
}
function total_num($sql)//取得记录总数
{
return odbc_num_rows($this->query($sql));
}
function close()//关闭数据库连接函数
{
odbc_close($this->link);
}
function insert($table,$field)//插入记录函数
{
$temp=explode(',',$field);
$ins='';
for ($i=0;$i
[php]
<?php
class Access//Access数据库操作类
{
var $databasepath,$constr,$dbusername,$dbpassword,$link;//类的属性
function Access($databasepath,$dbusername,$dbpassword)//构造函数
{
$this->databasepath=$databasepath;
$this->username=$dbusername;
$this->password=$dbpassword;
$this->connect();
}
function connect()//数据库连接函数
{
$this->constr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath($this->databasepath);
$this->link=odbc_connect($this->constr,$this->username,$this->password,SQL_CUR_USE_ODBC);
return $this->link;
//if($this->link) echo "恭喜你,数据库连接成功!";
//else echo "数据库连接失败!";
}
function query($sql)//送一个查询字符串到数据库中
{
return @odbc_exec($this->link,$sql);
}
function first_array($sql)//从access数据库中返回一个数组
{
return @odbc_fetch_array($this->query($sql));
}
function fetch_row($query)//返回记录中的一行
{
return odbc_fetch_row($query);
}
function total_num($sql)//取得记录总数
{
return odbc_num_rows($this->query($sql));
}
function close()//关闭数据库连接函数
{
odbc_close($this->link);
}
function insert($table,$field)//插入记录函数
{
$temp=explode(',',$field);
$ins='';
for ($i=0;$i
相关文章推荐
- PHP 长字符串替换操作性能(替换多换注释的代码)
- php下拉选项的批量操作的实现代码
- php操作XML、读取数据和写入数据的实现代码
- ACCESS 操作数据库代码
- PHP程序中使用PDO对象实现对数据库的增删改查操作的示例代码
- PHP文件读写操作之文件写入代码
- 30个php操作redis常用方法代码例子
- 30 个 php 操作 redis 常用方法代码例子
- php xml文件操作实现代码(二)
- php access 数据连接与读取保存编辑数据的实现代码
- 30个php操作redis常用方法代码例子
- php 操作access
- 一些php操作redis常用方法代码
- php调用dll的实例操作动画与代码分享
- php中使用redis队列操作实例代码
- 用PHP进行MySQL删除记录操作代码
- PHP文件操作实现代码分享
- PHP连接ACCESS操作
- php中的mongodb select常用操作代码示例
- 解析php DOMElement 操作xml 文档的实现代码