PHP Access data connection and read the implementation code to save the edited data

Source: Internet
Author: User
Tags driver manager dsn ole
 $conn = new COM ("ADODB. Connection "); $connstr = "Driver={microsoft Access DRIVER (*.mdb)}; Dbq= ". Realpath ("Www.jb51.net/db.mdb"); The COM interface is used to connect to the access. $conn->open ($CONNSTR); $rs = new COM ("ADODB. RecordSet "); The data is queried and displayed $rs->open ("SELECT * from szd_t", $conn, 1, 1); while (! $rs->eof) {$f = $rs->fields (1), echo $f->value; $rs->movenext ();}//Take a look at the PHP Access database tutorial Save $sql = "I Nsert into szd_t (title) VALUES (' www.jb51.net '); $rs->open ($sql); Echo ' Save success '; PHP Access database Edit $sql = "Update szd_t set title= ' jb51.net ' where id=". $_get[' id ']; $rs->open ($sql); Echo ' editing success '; Delete data $sql = "Delete from szd_t where id=". $_get[' id ']; 

PHP three ways to connect to an Access database
recently want to change an ASP Web site to PHP, helpless space does not support MySQL database, had to use Access database, but used to be used php+mysql,php+ Access database programming has not really been done.
Thank the party, thanks to CCTV, thanks to the search engine, this does not find a good article, special turn around and share with you.
There are 3 ways to connect to access in PHP.
(1) Create a system data source, which is provided by the ODBC function in PHP. The
(2) can also use PHP's ODBC functions, but does not create a data source. The
Open database connection (open Datebase Conection,odbc) is one of the windows open Server (open service) API (WOSA) products. A data source is a named connection to the database. An ODBC driver is required for the different types of databases that the application wants to connect to. The ODBC API is designed primarily for client/server RDBMS use, but ODBC drivers can also be used to connect desktop database files, worksheets, and flat files. ODBC uses the Odbcinst.dll library to set up and purge data sources. Odbcad32.exe is a stand-alone 32-bit executable application for establishing an ODBC data source, with its corresponding icon control Panel in the dashboard. The
ODBC Driver manager opens the ODBC driver for the data source and sends the SQL statement to the driver. After the client/server RDBMS finishes processing a select query, the ODBC driver returns the value to the application. When an INSERT, update, or DELETE statement is executed, the driver returns the number of rows affected by the query. Phperz.com
Below describes how PHP uses ODBC to connect to an Access database. Use $connstr= "driver= Microsoft Access DRIVER (*.mdb) to set up data-driven, function Realpath () to get the relative path of the database. Using this method to connect to an Access database is primarily applied to the PHP odbc_connect () function, which is declared as follows: Www.phperz.com

Resourse odbc_connect (String dsn, string user, string password [, int cursor_type]) DSN: System DSN name. User: The database server has a username. Password: A user password for the database server. Cursor_type: Cursor type.

The code is as follows:

$connstr = "Driver=microsoft Access DRIVER (*.mdb); Dbq= ". Realpath (" Bookinfo.mdb "); $connid =odbc_connect ($connstr, "", "", SQL_CUR_USE_ODBC);

(3) using Microsoft's ADODB database driver. ActiveX data Objects (ADO) is a database access technology for Microsoft Open database applications. It is designed to work together with the new data Access layer OLE DB provider to provide universal data access (Universal Date access). OLE DB is a low-level data access interface that provides access to a variety of data sources, including traditional relational databases, e-mail systems, and custom business objects. ADO technology greatly simplifies the operation of OLE DB because ADO encapsulates a large number of COM interfaces used in OLE DB programs, so ADO is a high-level access technology. PHP Programmer Station
ADO technology is based on the Common object Model (COM), which provides access techniques for multiple languages. PHP uses the ADO method to manipulate an Access database by pre-defining class COM. The class is described in detail as follows: www.phperz.com

String com::com (String module_name [, String server_name [, int codepage]]) Module_name: The name or Class-id of the requested component. Www~phperz~com the name of the server_name:dcom server. Codepage: Specifies the code page used to convert the PHP string to a Unicode string, and vice versa. The values for this parameter are CP_ACP, CP_MACCP, CP_OEMCP, Cp_symbol, CP_THREAD_ACP, Cp_utf7, and Cp_utf8. PHP uses the COM class and accesses the database using the ADO method as follows: [code] $conn = new COM ("ADODB. Connection "); $connstr = "Driver={microsoft Access DRIVER (*.mdb)}; Dbq= ". Realpath ("Bookinfo.mdb"); $conn->open ($CONNSTR);

This is an article sent by other netizens. Combined, the final script home will give a php+access message source code, we can refer to the next. Basically, the operation of PHP access is familiar.
Although it's very rare to use PHP to link to access, it's good to use the occasional guide data.

<? PHP/* Creates an ADO connection */$conn = @new COM ("ADODB. Connection ") or Die (" ADO Connection faild. "); $connstr = "Driver={microsoft Access DRIVER (*.mdb)}; Dbq= ". Realpath ("Datum/cnbt.mdb"); $conn->open ($CONNSTR); /* Create a Recordset query */$rs = @new COM ("ADODB. RecordSet "); $rs->open ("SELECT * from Dbo_dirs", $conn, 1, 3); /* loop to read data */while (! $rs->eof) {echo "$rs->fields[" title "]->value; echo "<br/>"; $rs->movenext (); Move the recordset pointer down} $rs->close ();?>

function description and examples
Although it's very rare to use PHP to link to access, it's good to use the occasional guide data.

Related Article

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.