When the client site is ASP + ACCESS platform how to transplant to the PHP platform? First of all, we want to solve the PHP Access database connection problem, without changing the database, PHP how to establish a connection with the Access database?
PHP provides a variety of connection database solutions, explain in detail how to use PHP ADOdb, PDO, ODBC and Access database connection instance code.
Ready to work
First, use PHP ADOdb to connect to the Access database
1, first of all you need to install PHP ADOdb class library.
2, use PHP ADOdb Access database code is as follows
Description: Using PHP ADOdb and Mysql database to establish a connection similar to the first ADOdb library included, and then call ADONewConnection, Connect, Execute and Access database to establish a connection and perform the query operation.
Second, use PHP PDO to connect Access database
PDO function need PHP5 above support, before using PDO you must ensure that the PDO function is installed, how to configure the installation of PDO?
Just find the extension_dir in your PHP.INI configuration file, point it to the extension's directory address, and remove the semicolon (;) before the PDO driver DLL you want to use. Restart Apache and PDO is installed. Here we use PDO to connect to the Access database, so at least to ensure php_pdo.dll, php_pdo_odbc.dll can support.
Use PDO to connect to the Access database code instance
<? $ db = new PDO ("odbc: driver = {microsoft access driver (* .mdb)}; dbq =". realpath ("access.mdb")) or die ("Connect Error");
Description: First initialize the PDO object, establish a connection between PHP and Access database, and then perform the query operation through the PDO query function.
Third, use ODBC to connect to the Access database
Use ODBC to connect to the Access database code instance
Description: First, use odbc_connect access database access, the first three parameters are: $ DSN, database user name, password, the fourth parameter is set to SQL_CUR_USE_ODBC Mainly in order to avoid accidental errors connecting Access database; Then use odbc_do query operation, And call odbc_fetch_row, odbc_result output query content, and finally close the Access database connection using odbc_close.
At this point the use of PHP ADOdb, PDO, ODBC access database and the operation of the code example is introduced, through the above example, we can see in fact PHP Access database access methods are more or less the same, which method to use depends on the configuration of the PHP environment.
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.