A PHP operation Access class php+odbc+access

Source: Internet
Author: User
Copy CodeThe code is as follows:


--------------------------------------------------------------------
FileName:class.php
Summary:access database Operation class
Author:forest
Createtime:2006-8-10
Lastmodifed:
Copyright (c) 2006 Freeweb.nyist.net/~chairy [Email]chaizuxue@163.com[/email]
Examples of Use:
$databasepath = "Database.mdb";
$dbusername = "";
$dbpassword = "";
Include_once ("class.php");
$access =new Access ($databasepath, $dbusername, $dbpassword);
--------------------------------------------------------------------
Class 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->c
$this->link=odbc_connect ($this->constr, $this->username, $this->password,sql_cur_use_odbc);
return $this->link;
if ($this->link) echo "Congratulations, database connection succeeded!";
else echo "Database connection failed!";
}
function query ($sql)
{
Return @odbc_exec ($this->link, $sql);
}
function First_array ($sql)
{
Return Odbc_fetch_array ($this->query ($sql));
}
function Fetch_row ($query)
{
Return Odbc_fetch_row ($query);
}
function Total_num ($sql)//Total number of records obtained
{
Return Odbc_num_rows ($this->query ($sql));
}
function close ()//Close database connection function
{
Odbc_close ($this->link);
}
function Insert ($table, $field)//Insert Record function
{
$temp =explode (', ', $field);
$ins = ";
for ($i =0; $i {
$ins. = "'". $_post[$temp [$i]]. "',";
}
$ins =substr ($ins, 0,-1);
$sql = "INSERT into". $table. " (". $field.") VALUES (". $ins.") ";
$this->query ($sql);
}
function GetInfo ($table, $field, $id, $colnum)//Get the record details
{
$sql = "SELECT * from". $table. " WHERE ". $field." = ". $id.";
$query = $this->query ($sql);
if ($this->fetch_row ($query))
{
for ($i =1; $i < $colnum; $i + +)
{
$info [$i]=odbc_result ($query, $i);
}
}
return $info;
}
function GetList ($table, $field, $colnum, $condition, $sort = "ORDER by ID DESC")//Get a list of records
{
$sql = "SELECT * from". $table. " ". $condition." ". $sort;
$query = $this->query ($sql);
$i = 0;
while ($this->fetch_row ($query))
{
$recordlist [$i]=getinfo ($table, $field, Odbc_result ($query, 1), $colnum);
$i + +;
}
return $recordlist;
}
function Getfieldlist ($table, $field, $fieldnum, $c//Get a list of records
{
$sql = "Select". $field. " From ". $table." ". $condition." ". $sort;
$query = $this->query ($sql);
$i = 0;
while ($this->fetch_row ($query))
{
for ($j =0; $j < $fieldnum; $j + +)
{
$info [$j]=odbc_result ($query, $j + 1);
}
$rdlist [$i]= $info;
$i + +;
}
return $rdlist;
}
function Updateinfo ($table, $field, $id, $set)//update record
{
$sql = "UPDATE". $table. " SET ". $set." WHERE ". $field." = ". $id;
$this->query ($sql);
}
function Deleteinfo ($table, $field, $id)//delete record
{
$sql = "DELETE from". $table. " WHERE ". $field." = ". $id;
$this->query ($sql);
}
function DeleteRecord ($table, $condition)//delete records for specified conditions
{
$sql = "DELETE from". $table. " WHERE ". $condition;
$this->query ($sql);
}
function Getcondrecord ($table, $c//number of records to get the specified condition
{
$sql = "Select COUNT (*) as num from". $table. " ". $condition;
$query = $this->query ($sql);
$this->fetch_row ($query);
$num =odbc_result ($query, 1);
return $num;
}
}
?>

The above describes a PHP operation Access class php+odbc+access, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.