Configuration and use of PHP database universal engine class adodb and instance highlights _ php instance

Source: Internet
Author: User
Tags db2 odbc driver ibm db2 ibm db2 odbc driver php database
ADODB is a compatible interface for various database applications (APIs. MySQL, PostgreSQL, Interbase, Firebird, Informix, Oracle, MSSQL7, Foxpro, Access, ADO, Sybase, FrontBase, DB2 adodb php database universal engine features:
1. you can standardize the connection and use of various databases in PHP.
2. it can help us provide development efficiency in PHP and quickly convert various databases
3. relatively simple to use
4. strict writing requirements, Case Sensitive
5. rich built-in functions

How to configure and use ADODB PHP
1. download the compressed package of the ADODB For PHP class library
2. decompress the package to any folder in the website directory.
3. introduce the ADODB configuration file
4. configure the required database connection
5. Use the built-in method to operate the connected database

Connect to MySql:

The code is 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 the MySQL database
?>

Access:

The code is as follows:


Include_once ("adodb/adodb. inc. php"); // contains the adodb class library file
$ Conn = NewADOConnection ('access'); // connect to the access Database
$ Conn-> Connect ("test. mb") or die ("cuowu ");
?>

Connect to DB2:

The code is as follows:


Include ("adodb/adodb. inc. php"); // contains the adodb class library file
$ Conn = NewADOConnection ('db2 '); // connect to the db2 database
$ Conn-> Connect ("driver = {IBM db2 odbc DRIVER}; database = mydb; hostname = localhost; port = 50000;
Protocol = TCPIP; uid = root; pwd = pass ");
?>

Connect to PostgreSQL:

The code is as follows:


Include ("adodb/adodb. inc. php"); // contains the adodb class library file
$ Conn = NewADOConnection ('seconds s ');
$ Conn-> Connect ('localhost', 'root', 'pass', 'mydb'); // Connect to the PostgreSQL database
?>


Fast query using ADODB PHP

The code is 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 );
}


Intelligent insertion using ADODB PHP

The code is 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' => '000000', '000000' => '000000 ');
$ Db-> AutoExecute ("up_admin_user", $ arr, "INSERT ");

Instance sharing:
Query:

The code is 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 the MySQL database
$ Db-> Execute ("set names 'gbk '");
$ Query = $ db-> Execute ("select * from think_zw ");
While ($ row = $ query-> FetchRow ()){
Print_r ($ row );
}
?>

Insert: When it is inserted, it will automatically filter out useless arrays. Exclude unused arrays.
Fields can be inserted with different values.

The code is 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 the MySQL database
$ Db-> Execute ("set names 'gbk '");
$ Arr = array ("id" => "",
"Name" => "Xiaojun ",
"Details" => "Xiaojun loves to watch beautiful women"); // do not write double quotation marks as single quotes
$ Db-> AutoExecute ("think_zw", $ arr, "INSERT ");
$ Query = $ db-> Execute ("select * from think_zw ");
While ($ row = $ query-> FetchRow ()){
Echo $ row [name]."
";
}
?>

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

Php adodb address connection to the database:

The code is as follows:


Include_once ("adodb5/adodb. inc. php ");
$ Db = NewADOConnection ('MySQL: // root: @ localhost/upload ');
$ SQL = "SELECT * FROM 'Pic '";
$ Db-> SetFetchMode (ADODB_FETCH_ASSOC); // The difference between ADODB_FETCH_NUM and fetch_array is similar.
// Mysql_fetch_array ()
$ Sr1 = $ db-> Execute ($ SQL );
Print_r ($ sr1-> fields );

Php adodb object method for retrieving database content

The code is as follows:


$ Db = NewADOConnection ('mysql ');
$ Db-> PConnect ("localhost", "root", "", "upload ");
$ SQL = "SELECT * FROM 'Pic '";
$ Rs2 = $ db-> Execute ($ SQL );
While ($ row = $ rs2-> FetchNextObject ()){
Echo $ row-> NAME;
}

Php adodb html code display content

The code is as follows:


Include_once ("adodb5/tohtml. inc. php ");
$ Db = NewADOConnection ('mysql ');
$ Db-> Connect ("localhost", "root", "", "upload ");
$ SQL = "SELECT * FROM 'Pic '";
$ Rs2 = $ db-> Execute ($ SQL );
Echo rs2html ($ rs2 );

Php adodb implements automatic content paging

The code is 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 );

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.