ADODB PHP Database Universal engine class features:
1. Can be used in PHP to standardize the links and use of various types of databases
2. can help us in PHP to provide development efficiency and rapid conversion of various types of databases
3. Relatively simple to use
4. Writing requirements more rigorous, attention to the case
5. Built-in functions are relatively rich
How to configure and use ADODB PHP
1. Download ADODB for PHP Class Library compression package
2. Extract to the Site directory under any folder under
3. Introduction of ADODB configuration file
4. Configure the required database connections
5 using built-in methods to manipulate linked databases
Connect MySQL:
Copy Code code as follows:
<?php
Include_once ("adodb5/adodb.inc.php"); Contains ADODB class library files
$db = newadoconnection (' mysql ');
$db->connect (' localhost ', ' root ', ' root ', ' test ') or Die ("df"); Connecting to the MySQL database
?>
Connect to access:
Copy Code code as follows:
<?php
Include_once ("adodb/adodb.inc.php"); Contains ADODB class library files
$conn = newadoconnection (' access '); Connect to an Access database
$conn->connect ("test.mb") or Die ("Cuowu");
?>
Connection DB2:
Copy Code code as follows:
<?php
Include ("adodb/adodb.inc.php"); Contains ADODB class library files
$conn =newadoconnection (' DB2 '); Connecting to the DB2 database
$conn->connect ("DRIVER={IBM DB2 ODBC driver};d atabase=mydb;hostname=localhost;port=50000;
Protocol=tcpip;uid=root; Pwd=pass ");
?>
Connection PostgreSQL:
Copy Code code as follows:
<?php
Include ("adodb/adodb.inc.php"); Contains ADODB class library files
$conn = newadoconnection (' Postgres ');
$conn->connect (' localhost ', ' root ', ' pass ', ' mydb '); Connecting to the PostgreSQL database
?>
ADODB PHP to implement the fast query function
Copy 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 Implementation Intelligent Insert function
Copy 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 Code code as follows:
<?php
Include_once ("adodb5/adodb.inc.php"); Contains ADODB class library files
$db = newadoconnection (' mysql ');
$db->connect (' localhost ', ' root ', ', ', ' think_zw ') or Die ("error"); Connecting to the 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 the useless array when it is inserted. Exclude arrays that are not used.
Fields can be inserted without corresponding inserts.
Copy Code code as follows:
<?php
Include_once ("adodb5/adodb.inc.php"); Contains ADODB class library files
$db = newadoconnection (' mysql ');
$db->connect (' localhost ', ' root ', ', ', ' think_zw ') or Die ("error"); Connecting to the MySQL database
$db->execute ("Set names ' GBK '");
$arr =array ("id" => "",
"Name" => "Small Army",
"Details" => "small army love to see Beautiful woman");/note do not write double quotes in single quotes
$db->autoexecute ("Think_zw", $arr, "INSERT");
$query = $db->execute ("SELECT * from THINK_ZW");
while ($row = $query->fetchrow ()) {
echo $row [name]. <br> ";
}
?>
===============================
PHP ADODB Address way to connect to the database:
Copy 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 It's a little bit like that 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 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 display content
Copy 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 Implement content automatic paging function
Copy 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);