Home Backend Development PHP Tutorial A collection of commonly used php ADODB usage methods in dob

A collection of commonly used php ADODB usage methods in dob

Jul 29, 2016 am 08:37 AM

Copy the code The code is as follows:

​​​​​​​​                                           $DB_PASS                                                                                                                                                                                                                                                          part”; DEBUG test, the default value is false

$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;//Returned recordset form, associated form
/***
Returned recordset form
define('ADODB_FETCH_DEFAULT',0);​​
define('ADODB_FETCH_NUM ', 1); fDefine (' Adodb_fetch_assoc ', 2);
Define (' Adodb_fetch_both ', 3);
The above constant, is defined in adodb.inc.php, that is, you can use "$ adodb_fetch_mode = 2 "Method 方式ADODB_FETCH_NUM The index in the record set returned is in numeric form, that is, the sort order value of the database field
ADODB_FETCH_ASSOC The index in the record set returned is the original database field name
ADODB_FETCH_BOTH and ADODB_FETCH_DEFAULT return the above two at the same time.Some databases do not support
An example:
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs1 = $db->Execute('select * from table');
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rs2 = $db->Execute ('Select*from table');
Print_r ($ RS1- & GT; Fields);#The array returned is: array ([0] = & gt; 'v0', [1] = & gt; 'v1')
print_r. ($rs2->fields); # The returned array is: array(['col1']=>'v0',['col2'] =>'v1')                                                                                                                                                                             Database, methods include Connect, PConnect, NConnect, generally use Connect
if (!@$db->Connect("$DB_HOST", "$DB_USER", "$DB_PASS", "$DB_DATABASE")) {                                 exit( 'The server is busy, please visit again later'); ($sql), execute the $sql statement in the parameters ​​
SelectLimit($sql,$numrows=-1,$offset=-1) $numrows: how many records are taken, $offset, which record to start from, usually Used for paging, or when only fetching a few records
*/
//Example: Fetching multiple records
$sql = "Select * FROM table orDER BY id DESC";
if (!$rs = $db- & gt; Execute ($ SQL)) {// execute the SQL statement, and return the result to the $ RS variable
echo $ db- & gt; errormsg (); // ;//Close the database                                                                                     ; ';
                    //                                                                                       using   use   with using                                     out out out out outmbps outmbps out out Over’s’ to be's to be Point to the next record, otherwise an infinite loop will occur!
}& $ Rs- & gt; close (); // Close to release memory
// Insert new records
$ SQL = "Insert Table (user_type, username) (3, 'liucheng')" "";
$ db- & gt; Execute($sql);                                                                                                                                                                             having
$sql = " Delete FROM table Where id=2";                                                                                                                                                                                                  $db-> Array, error returns false                                                                             using​​
echo 'I didn't find this record';
exit ();
} Else {
echo $ data_ary ['username']. ''. $ data_ary ['password']. ''. $ data_ary ['user_type']. '.
';            
}                                                                                                                                                                                                                 . sql ; result = $rs->FetchRow()) {
echo 'This record was not found'; '< ;br>';                                             
//Get a single field
//$db->GetOne($sql) Get the value of the first field of the first record, return false if an error occurs
$sql = "Select COUNT(id) FROM table";
$record_nums = $db->GetOne($sql); b->GetOne( $sql);
echo $result;//Print out the value of username
/*
When adding, modifying, or deleting records,
Use $db->qstr() for string fields The characters entered by the user are processed.
For numeric fields, data judgment is required
Update records. Note: This is for the case where magic_quotes is set to Off in php.ini. If you are not sure, you can use
$db-> ;qstr($content,get_magic_quotes_gpc())
Note: c
*/
$sql = "Update table SET c
$db->Execute($sql);
/*$db- >Insert_ID() , no parameters, returns the ID value of the record just inserted, only supports some databases, databases with auto-increment function, such as PostgreSQL, MySQL and MS SQL
*/
//Example:
$sql = "Insert table (user_type,username) VALUES (3, 'liucheng')"; "
$db->Execute($sql); "
/*$db ->GenID($seqName = 'adodbseq',$startID=1), generates an ID value. $seqName: the database table name used to generate this ID, $startID: the starting value, generally does not need to be set, it will The value in $seqName is automatically increased by 1. Supports some databases, some databases do not support
Insert_ID, GenID. Generally, I use GenID. The purpose of using it is to get its ID immediately after inserting the record.
*** -& gt; Genid ('user_id_seq');
$ SQL = "Insert Table (ID, User_type, Username) Values ​​(". $ User_id. ", 3, 'LiuCheng')");
$ db-& gt; e XECUTE ($ sql);*/*
$ rs- & gt; recordcount (), the total number of record sets is taken out, no parameter
It seems to be the method of using the recording of the draw, the number of data in the array of the count () array, if you take a lot of data, if you take a lot of data , the efficiency is relatively slow. It is recommended to use the COUNT(*) method in SQL.
*/
$sql = "Select * FROM table orDER BY id DESC";
if (!$rs = $db->Execute($sql)) { echo $db->ErrorMsg( ); db->Close(); 
$record_nums = $rs->RecordCount();
/*
If you want to perform the same loop processing twice on a certain result set, you can use the following method
The following is just an example, just to illustrate $rs ->How to use MoveFirst()
*/
$sql = "Select * FROM table orDER BY id DESC";
if (!$rs = $db->Execute($sql)) {
echo $db ->ErrorMsg(); ->EOF) {                                                                                                                                           $ RS-& GT; Fields ['Username']
Echo $ RS- & GT; Fields ['Username']. '& LT; Br & GT; // Print_r ($ RS- & GT; Fields) Try, $ RS- & G T ;fields['Field name'], returns the value in this field                                                                                                                                                                                                                                                                 ; = array_unique($username_ary); ; '] . '
';//print_r($rs->fields) try, $rs->fields['field name'], what is returned is the value in this field    
  $rs-> ;MoveNext(); // Point the pointer to the next record                                                                                                                                                                                                                                                                                    ; ;
?>


The above has introduced a collection of commonly used php ADODB usage methods for dob, including dob content. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1672
14
PHP Tutorial
1277
29
C# Tutorial
1257
24
Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO) How do you prevent SQL Injection in PHP? (Prepared statements, PDO) Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

See all articles