Php simple method of using PDO in the Database abstraction layer, PHP database abstract PDO
This paper describes the simple use of PDO in the database abstraction layer by PHP. Share to everyone for your reference, as follows:
The test code is as follows:
<?php/************************** @Filename: pdotest.php@content:pdo operation mysql,access (test) ************************ **/if ($_get[' db '] = = ' MySQL ') {$dns = ' mysql:host=localhost;dbname=test '; $dbuser = ' root '; $dbpass = ' root '; $db = new PDO ($dns, $dbuser, $dbpass);} else{$db = new PDO ("Odbc:driver={microsoft Access Driver (*.mdb)};D bq=". GETCWD (). " Test.mdb ");} if ($_post[' reg ']) {$db->exec ("INSERT into T_user (name,email) VALUES ('". $_post[' name ']. "', '". $_post[' email ']. "') ; Header (' Location: '. $_server[' php_self '); ?> return <?} else{$html = "; $re = $db->query ("Select Uid,name,email from T_user ORDER by email;"); while ($rs = $re->fetch ()) {$userlisthtml. = ''. $rs [' uid ']. ''. $rs [' name ']. ''. $rs [' email ']. ''; } $html. = '
User List
ID |
Name |
Email |
'. $userlisthtml. '
';} Echo $html;? >
Test environment:
php.ini file: Open extension=php_pdo_odbc.dll Remove semicolon open aceess database driver
MySQL is turned on by default
Access path:
MySQL Database
Http://192.168.1.21/lava_guess2009/test/pdo/pdotest.php?db=mysql
Aceess Database
http://192.168.1.21/lava_guess2009/test/pdo/pdotest.php
Features: Using different databases as long as the connection driver can be changed, the code does not make any changes, that is, the benefits of abstraction layer.
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1067840.html www.bkjia.com true http://www.bkjia.com/PHPjc/1067840.html techarticle PHP in the database abstraction layer simple use of PDO method, PHP database Abstract PDO This article describes the PHP in the database abstraction layer simple use of PDO method. Share to everyone for your reference, specific ...