CopyCode The Code is as follows: $ conn = new COM ("ADODB. Connection ");
$ Connstr = "driver = {Microsoft Access Driver (*. mdb)}; DBQ =". realpath ("www.jb51.net/db.mdb ");
// The COM interface is required for connecting to access.
$ Conn-> open ($ connstr );
$ Rs = new COM ("ADODB. recordset ");
// Query and display data
$ RS-> open ("select * From szd_t", $ Conn, 1, 1 );
While (! $ RS-> EOF ){
$ F = $ RS-> fields (1 );
Echo $ F-> value;
$ RS-> movenext ();
}
// The following describes how to save the PHP Access Database tutorial.
$ SQL = "insert into szd_t (title) values ('www .jb51.net ')";
$ RS-> open ($ SQL );
Echo 'saved successfully ';
// Edit the PHP Access Database
$ SQL = "Update szd_t set Title = 'jb51. net' where id =". $ _ Get ['id'];
$ RS-> open ($ SQL );
Echo 'edited successfully ';
// Delete data
$ SQL = "delete from szd_t where id =". $ _ Get ['id'];
Three methods for connecting PHP to the Access Database
Recently I want to change an ASP Website to PhP, but the space does not support MySQL databases, so I have to use the ACCESS database, but I used PHP + MySql in the past, PHP + ACCESS database programming has never been done yet.
Thanks to the party, CCTV, and the search engine. Article To share with you.
There are three methods to connect to access in PHP.
(1) Create a system data source and use the ODBC function provided by PHP.
(2) You can also use the ODBC function of PHP without creating a data source.
Open datebase conection (ODBC) is one of Windows Open Server APIs (wosa. A data source is a named connection to the database. For applications Program An ODBC driver is required for different types of databases to be connected. ODBC APIs are mainly designed for RDBMS users/servers. However, ODBC drivers can also be used to connect desktop database files, worksheets, and flat files. ODBC uses the odbcinst. dll library to set and clear data sources. Odbcad32.exe is an independent 32-bit executable application used to create an ODBC data source. It has its corresponding icon control panel in the control panel.
The ODBC driver manager opens the ODBC driver for the data source and sends SQL statements to the driver. After the Client/Server RDBMS processes 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
The following describes how to use ODBC to connect to the ACCESS database in PHP. Use $ connstr = "driver = Microsoft Access Driver (*. mdb) to set the data driver. The realpath () function is used to obtain the relative path of the database. This method is used to connect the Access database to the odbc_connect () function of PHP. The function declaration is as follows: www.phperz.com Copy code The Code is as follows: resourse odbc_connect (string DSN, string user, string password [, int cursor_type])
DSN: the name of the system DSN.
User: User Name of the database server.
Password: Password of a user on the database server.
Cursor_type: cursor type.
The Code is as follows:Copy codeThe Code is as follows: $ connstr = "driver = Microsoft Access Driver (*. mdb );
DBQ = ". realpath (" bookinfo. mdb ");
$ Connid = odbc_connect ($ connstr, "", "", SQL _cur_use_odbc );
(3) Use Microsoft's ADODB database driver. ActiveX Data Objects (ADO) is a database access technology for Microsoft open database applications. It is designed to work with the new data access layer ole db provider to provide universal data access ). Ole db is a low-level data access interface that can be used to access various data sources, including traditional relational databases, email systems, and custom business objects. ADO technology greatly simplifies ole db operations, because ADO encapsulates a large number of COM interfaces used in ole db programs, so ADO is a high-level access technology. PHP programmer site
Based on the Common Object Model (COM), ADO provides access technology in multiple languages. PHP uses a pre-defined class com to manipulate the ACCESS database using the ADO method. This class is described in detail as follows: www.phperz.comCopy codeThe Code is as follows: String COM: COM (string module_name [, string SERVER_NAME [, int codePage])
Module_name: Name or class-ID of the requested component. WWW ~ Phperz ~ Com
SERVER_NAME: name of the DCOM server.
CodePage: Specifies the code page used to convert a PHP string to a unicode string, and vice versa. The optional values include cp_acp, cp_maccp, cp_oemcp, cp_symbol, cp_thread_acp, cp_utf7, and cp_utf8.
PHP uses the com class and ADO method to access the database:
[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 network friends. In combination, the script home will provide a message source code for PHP + ACCESS. For more information, see. I am familiar with PHP access operations.
Although PHP is rarely used to link access, it is quite good to occasionally use it to export data.Copy codeThe Code is as follows: <? PHP
/*
Create 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 record set Query
*/
$ Rs = @ new COM ("ADODB. recordset ");
$ RS-> open ("select * From dbo_dirs", $ Conn, 1, 3 );
/*
Read data cyclically
*/
While (! $ RS-> EOF ){
Echo "$ RS-> fields [" title "]-> value;
Echo "<br/> ";
$ RS-> movenext (); // move the record set pointer down
}
$ RS-> close ();
?>
Function Description and example
Although PHP is rarely used to link access, it is quite good to occasionally use it to export data.
PHP access simple message source code