clear version of ten examples of dob Adodb
I originally wanted to learn pear, but I saw several posts on the Internet that rated adodb very highly, so I changed to this one.
ADODB has the following advantages (said online, not mine):
1. It is twice as fast as pear;
2. It supports many more database types than pear, and can even support ACCESS;
3. No need Installation, no server support is required (for novices, this is very important)
Friends who don’t know what adodb is or want to download adodb can go to this link: http://www.phpe.net/class/106 .shtml
In addition, if any brother has translated the full text of the README or knows where to find the translation, please reply to me, thank you.
Tutorial
Example 1: Select Statement
Task: Connect to an Access database named Northwind and display the first two fields of each record.
In this example, we created a new ADOC connection (ADOConnection) object and used it to Connect to a database. This connection uses the PConnect method, which is a persistent connection. When we want to query the database, we can call the Execute() function of this connection at any time. It will return an ADORecordSet object which is actually a cursor that holds the current row in the array fields[]. We use MoveNext() to move from one record to the next.
NB: There is a very practical function SelectLimit not used in this example, which can control the number of records displayed (such as Only the first ten records are displayed and can be used for paging display).
PHP:---------------------------------- -----------------------------------------------
include('adodb.inc.php'); #Load ADOdb
$conn = &ADONewConnection('access'); # Create a new connection
$conn->PConnect('northwind'); # Connect to a file named northwind's MS-Access database
$recordSet = &$conn->Execute('select * from products'); #Search all data from the products data table
if (!$recordSet)
print $conn->ErrorMsg (); //If an error occurs during data search, display error message
else
while (!$recordSet->EOF) {
print $recordSet->fields[0].' '.$recordSet->fields[1 ].'
';
$recordSet->MoveNext(); //Point to the next record
} //List display data
$recordSet->Close(); //Optional
$conn- >Close(); //Optional
?>
---------------------------------- ---------------------------------------------
$recordSet in $ The current array is returned in recordSet->fields, and the fields are numerically indexed (starting from 0). We use the MoveNext() function to move to the next record. When the database search reaches the end, the EOF property is set to true. If Execute() An error occurs, recordset returns false.
$recordSet->fields[] array is generated from PHP database extension. Some database extensions can only be indexed by numbers and not by field names. If you insist on using field name indexes, you should use the SetFetchMode function. Regardless of the format of the index, the recordset can be created by Execute() or SelectLimit().
PHP:---------------------------------------------------------- ----------------------------------
$db->SetFetchMode(ADODB_FETCH_NUM);
$rs1 = $db ->Execute('select * from table'); //Use numeric index
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$rs2 = $db->Execute('select * from table'); // Using field name index
print_r($rs1->fields); # shows array([0]=>'v0',[1] =>'v1')
print_r($rs2->fields); # shows array(['col1']=>'v0',['col2'] =>'v1')---------------------- -------------------------------------------------- --------
If you want to get the record number, you can use $recordSet->RecordCount(). Returns -1 if there is no current record.
Example 2: Advanced Select with Field Objects
Search the table and display the first two fields. If the second field is in time or date format, change it to US standard time format.
PHP:------ -------------------------------------------------- --------------------------
include('adodb.inc.php'); ///Load adodb
$conn = &ADONewConnection('access'); //Create a new connection
$conn->PConnect('northwind'); //Connect to the MS-Access database named northwind
$recordSet = &$conn->Execute('select CustomerID,OrderDate from Orders'); //Search the CustomerID and OrderDate fields from the Orders table
if (!$recordSet)
print $conn->ErrorMsg(); //If the database search error occurs, the error message is displayed
else
while (!$recordSet->EOF) {
$fld = $recordSet->FetchField(1); //Assign the second field to $fld
$type = $recordSet->MetaType($ fld->type); //Format of getting field value
if ( $type == 'D' || $type == 'T')
print $recordSet->fields[0].' '.
$recordSet->UserDate($recordSet->fields[1],'m/d/Y').'
'; //If the field format is date or time, make it in American standard format Output
else
print $recordSet->fields[0].' '.$recordSet->fields[1].'
'; // Otherwise, output as is
$recordSet->MoveNext() ; //Point to the next record
}
$recordSet->Close(); //Optional
$conn->Close(); //Optional
?>
-------- -------------------------------------------------- --------------------------
In this example, we use the FetchField() function to check the format of the second field. It returns a field containing three The object of the variable
name: field name
type: the actual format of the field in its database
max_length: the maximum length of the field, some databases will not return this value, such as MYSQL, in this case the max_length value is equal to -1.
We use MetaType() converts the database format of the field into a standard field format
C: Character field, which should be displayed under the tag.
X: Text field, which stores relatively large fields Text, generally used in
以上就介绍了dob Adodb的十个实例清晰版,包括了dob方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
