search
HomeBackend DevelopmentPHP TutorialA collection of commonly used php ADODB usage methods in dob

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
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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.