Php access database operation method

Source: Internet
Author: User
Tags php website
This article mainly introduces how to operate the access database in php, detailed analysis of php connection and operation of the access database based on ADOdb, PDO, ODBC, and other methods combined with the instance form. the specific implementation skills and related precautions are as follows, for more information, see the following example. We will share this with you for your reference. The details are as follows:

In PHP website development, PHP and Mysql are the best combination, but when you want to port websites on other platforms to the PHP platform, you will inevitably encounter portability problems, for example, how can I port an ASP + ACCESS platform? The first challenge is how PHP connects to the Access database. without changing the database, how does PHP establish a connection with the Access database?

PHP provides a variety of database connection solutions. here, we will explain how to use PHP ADOdb, PDO, ODBC and Access database to establish a connection code instance.

Preparations

Use OFFICE tools to create Access database files

1. use PHP ADOdb to connect to the Access Database

1. First, you need to install the PHP ADOdb class library.

2. use PHP ADOdb to connect to the Access database:

 Connect($dsn);  $rs = $db->Execute('select * from web');  print "
";  print_r($rs->GetRows());  print "
";?>

Note: Similar to using PHP ADOdb to establish a connection with a Mysql database, first include The ADOdb class library, and then call ADONewConnection, Connect, and Execute to establish a connection with the Access database and perform query operations.

2. use php pdo to connect to the Access Database

The PDO function must be supported by PHP5 or above. before using PDO, you must ensure that the PDO function is installed. how can you configure and install PDO?

In PHP. find extension_dir in The INI configuration file, point it to the extension Library Directory address, remove the semicolon (;) before the PDO driver DLL you want to use, restart Apache, and install PDO. Because we use PDO to connect to the Access database, we must at least ensure that php_pdo.dll and php_pdo_odbc.dll are supported.

Use PDO to connect to the Access database code instance

 query('select * from web');  print "
";  print_r($rs->fetchAll());  print "
";?>

Note: first initialize the PDO object, establish a connection between PHP and the Access database, and then use the PDO query function to perform the query operation.

3. use ODBC to connect to the Access Database

Connect to the Access database code instance using ODBC

 Website address: ". odbc_result ($ rs," website ");} odbc_close ($ conn);?>

Note: First, use odbc_connect to connect to the access Database. the first three parameters are $ DSN, database username, and password, the fourth parameter is SQL _CUR_USE_ODBC, which is used to avoid unexpected errors when connecting to the Access database. Then, use odbc_do to perform the query operation and call odbc_fetch_row and odbc_result to output the query content, finally, use odbc_close to close the Access database connection.

Now, we have introduced the code instances for connecting to and operating the Access database using PHP ADOdb, PDO, and ODBC. through the above examples, we can see that the methods for connecting to the Access database using PHP are similar, which method is used depends on the configuration of the PHP environment.

For more articles on how to operate the access database in php, refer to the Chinese PHP website!

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.