PHP operations class sharing for Access databases

Source: Internet
Author: User
This article describes a class of PHP operations Access database, with the need for a friend reference.

The code is as follows:

     GetList ("Select TOP 5 * from ' Result ' WHERE ' Resultno ' < [ORDER by ' Resultno ' DESC")); Echo $access->num_rows ("Upda Te ' Conner ' set ' connerip ' = ' 222.35.142.101 ' where ' Connerno ' < "); */class access{var $databasepath, $constr, $dbu    Sername, $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)};D bq= '. Realpath ($this    DatabasePath). '; ';    $this->link=odbc_connect ($this->constr, $this->username, $this->password,sql_cur_use_odbc);    if (! $this->link) echo "Database connection failed!"; return $this->link;} function query ($sql) {//Run SQL directly, can be used to update, delete data return @odbc_exec ($this->link, $sql);} function Fetch_array ($query) {//Gets record return Odbc_fetch_array ($query) at current pointer;} function Fetch_row ($query) {//basic same as Fetch_array(), but only the numeric index return Odbc_fetch_row ($query);} function Num_rows ($sql) {//returns the number of rows affected by the SQL query return Odbc_num_rows ($this->query ($sql));} function Close () {//Close database connection function odbc_close ($this->link);}    function GetList ($sql) {//get record list $query = $this->query ($sql);    $recordlist =array ();    while ($row = $this->fetch_array ($query)) {$recordlist []= $row; } return $recordlist;}}? >

ODBC is used in the above classes instead of ODBC data sources. Create a new *.mdb file directly to use.

Attached, some common COM ways to manipulate access code:

 
      Open ("Driver={microsoft Access DRIVER (*.mdb)}; dbq= $db ");? >

JS Call page js.php

     Execute ("Select TOP 3 * from Userstar where chk = 1 ORDER by ID DESC"); $IDGB =1;while (! $rs->eof) {$gbinf [$IDGB] [' ID ']    = $rs->fields[' id ']->value;    $gbinf [$IDGB] [' usname '] = $rs->fields[' usname ']->value;    $gbinf [$IDGB] [' usage '] = $rs->fields[' usage ']->value;    $gbinf [$IDGB] [' usprovince '] = $rs->fields[' usprovince ']->value;    $gbinf [$IDGB] [' usfile '] = $rs->fields[' usfile ']->value;    $gbinf [$IDGB] [' thumb '] = $rs->fields[' thumb ']->value;    $gbinf [$IDGB] [' usmessage '] = $rs->fields[' usmessage ']->value;    $rs->movenext (); $IDGB + +;} $rs->close (); $rs = null; $uhtml = "; $uhtml. = '
     
     
         ' For ($i =1; $i <4; $i + +) {$uhtml. = ' 
        ';} $uhtml. = ' 
       
'; if ($gbinf [$i] [' usfile ']) {$uhtml. = '
'. $gbinf [$i] [' usprovince ']. ' '. $gbinf [$i] [' usname ']; if ($gbinf [$i] [' usage ']! = 0) {$uhtml. = ' ('. $gbinf [$i] [' usage ']. ' Years
'; } $uhtml. = '. $gbinf [$i] [' usmessage ']. '; } $uhtml. = '
'; Echo ' document.write (' $uhtml. ') ';? >

Another example is to determine the database path with this file path:

open ("Driver={microsoft Access DRIVER (*.mdb)}; dbq= $db "),//print_r ($_post), if ($_post[' name ') && $_post[' Tel '] && $_post[' addr '] && $_post[' Email '] && $_post[' goal '] && $_post[' high '] && $_post[' weight '] && $_post[' message ') { $addsql = "INSERT into d90usr (' name ', ' Tel ', ' addr ', ' e-mail ', ' goal ', ' high ', ' weight ', ' message ') VALUES ('". $_post[' Nam E ']. "', '". $_post[' Tel ']. "', '". $_post[' addr ']. "', '". $_post[' email ']. "', '". $_post[' goal ']. "', '". $_post[' High '. " , ' ". $_post[' weight ']." ', ' ". Strip_tags ($_post[' message '])." ') "; /echo ' 
       '. $addsql; $rsadd = $conn->execute ($addsql); Echo ' 

Congratulations on your successful registration. Please wait for the staff to contact you!

'; Echo '

Return to activity home page back to mall home

';}?
  • 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.