PHP Database Universal engine Class ADODB configuration usage and example Collection _php tutorial

Source: Internet
Author: User
Tags db2 db2 odbc driver ibm db2 ibm db2 odbc driver php database
ADODB PHP Database Universal engine class features:
1. Can be in the PHP specification of various types of database links and use
2. Can help us to provide development efficiency in PHP and quickly convert various databases
3. Relatively simple to use
4. Writing requirements more rigorous, pay attention to the case
5. Rich built-in functions

How to configure and use ADODB PHP
1. Download ADODB for PHP Class Library compression package
2. Unzip to any folder under the Site Directory
3. Introduction of the ADODB configuration file
4. Configure the required database connections
5 using built-in methods to manipulate linked databases

To connect to MySQL:

Copy the Code code as follows:
Include_once ("adodb5/adodb.inc.php"); Contains the ADODB class library file
$db = newadoconnection (' mysql ');
$db->connect (' localhost ', ' root ', ' root ', ' test ') or Die ("df"); Connect to MySQL Database
?>

Connect to access:

Copy the Code code as follows:
Include_once ("adodb/adodb.inc.php"); Contains the ADODB class library file
$conn = newadoconnection (' access '); Connect to an Access database
$conn->connect ("test.mb") or Die ("Cuowu");
?>

Connection DB2:

Copy the Code code as follows:
Include ("adodb/adodb.inc.php"); Contains the ADODB class library file
$conn =newadoconnection (' DB2 '); Connecting the DB2 Database
$conn->connect ("DRIVER={IBM DB2 ODBC driver};d atabase=mydb;hostname=localhost;port=50000;
Protocol=tcpip;uid=root; Pwd=pass ");
?>

Connect PostgreSQL:

Copy the Code code as follows:
Include ("adodb/adodb.inc.php"); Contains the ADODB class library file
$conn = newadoconnection (' Postgres ');
$conn->connect (' localhost ', ' root ', ' pass ', ' mydb '); Connect to PostgreSQL Database
?>


ADODB PHP for fast query function

Copy the Code code as follows:
Include_once ("adodb5/adodb.inc.php");
$db = &newadoconnection (' mysql ');
$db->connect ("localhost", "root", "" "," db ") or Die (" error ");
$db->execute ("Set names ' GBK '");
$q = $db->execute ("SELECT * from Up_admin_user");
while ($row = $q->fetchrow ()) {
Print_r ($row);
}


ADODB PHP for smart Insert function

Copy the Code code as follows:
Include_once ("adodb5/adodb.inc.php");

$db = &newadoconnection (' mysql ');
$db->connect ("localhost", "root", "" "," db ") or Die (" error ");
$db->execute ("Set names ' GBK '");

$arr =array (' m_id ' = ' 2 ', ' password ' = ' 333333 ', ' 33333 ' = ' 4444444 ');
$db->autoexecute ("Up_admin_user", $arr, "INSERT");

Example sharing:
Inquire:

Copy the Code code as follows:
Include_once ("adodb5/adodb.inc.php"); Contains the ADODB class library file
$db = newadoconnection (' mysql ');
$db->connect (' localhost ', ' root ', ' ', ' think_zw ') or Die ("error"); Connect to MySQL Database
$db->execute ("Set names ' GBK '");
$query = $db->execute ("SELECT * from THINK_ZW");
while ($row = $query->fetchrow ()) {
Print_r ($row);
}
?>

Insert : It automatically filters out unused arrays when plugged in. Exclude arrays that are not used.
Fields can be inserted without corresponding inserts.

Copy the Code code as follows:
Include_once ("adodb5/adodb.inc.php"); Contains the ADODB class library file
$db = newadoconnection (' mysql ');
$db->connect (' localhost ', ' root ', ' ', ' think_zw ') or Die ("error"); Connect to MySQL Database
$db->execute ("Set names ' GBK '");
$arr =array ("id" = "",
"Name" = "Small Army",
"Details" and "small army love to see beautiful women";//pay attention not to enclose double quotation marks in single quotation marks
$db->autoexecute ("Think_zw", $arr, "INSERT");
$query = $db->execute ("SELECT * from THINK_ZW");
while ($row = $query->fetchrow ()) {
echo $row [name]. "
";
}
?>

===============================

PHP ADODB address mode to connect to the database:

Copy the Code code as follows:
Include_once ("adodb5/adodb.inc.php");
$db = Newadoconnection (' mysql://root: @localhost/upload ');
$sql = "select * from ' pic '";
$db->setfetchmode (ADODB_FETCH_ASSOC),//adodb_fetch_num here is a little bit like the Fetch_array and Fetch_row.
Mysql_fetch_array ()
$SR 1 = $db->execute ($sql);
Print_r ($SR 1->fields);

PHP ADODB Object way to get database content

Copy the Code code as follows:
$db = newadoconnection (' mysql ');
$db->pconnect ("localhost", "root", "" "," upload ");
$sql = "select * from ' pic '";
$rs 2= $db->execute ($sql);
while ($row = $rs 2->fetchnextobject ()) {
Echo $row->name;
}

PHP ADODB HTML code way to display content

Copy the Code code as follows:
Include_once ("adodb5/tohtml.inc.php");
$db = newadoconnection (' mysql ');
$db->connect ("localhost", "root", "" "," upload ");
$sql = "select * from ' pic '";
$rs 2= $db->execute ($sql);
Echo rs2html ($rs 2);

PHP ADODB for content auto-paging functionality

Copy the Code code as follows:
Include_once ("adodb5/adodb-pager.inc.php");
Session_Start ();
$db = newadoconnection (' mysql ');
$db->connect ("localhost", "root", "" "," upload ");
$db->execute ("Set names ' GBK '");
$sql = "select * from ' pic '";
$pager =new Adodb_pager ($db, $sql);
$pager->render (2);

http://www.bkjia.com/PHPjc/788639.html www.bkjia.com true http://www.bkjia.com/PHPjc/788639.html techarticle ADODB PHP Database Universal Engine class features: 1. Can be in the PHP specification of various types of database links and use 2. can help us to provide development efficiency in PHP and quickly convert all kinds of databases 3. Use Phase ...

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