Php simple method of using PDO in the Database abstraction layer, PHP database Abstraction pdo_php Tutorial

Source: Internet
Author: User
Tags php database

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. = '
 
 
    '. $userlisthtml. ' 
  
User List
ID Name Email
';} 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 ...

  • 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.