phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


ADOdb: Advance Select Statement

Tag: adodb, database, database layer   Category: PHP Database
post: 29 Oct 2007 read: 1,773


ADOdb have features that help finishing your work faster. A good feature is advance select. You can improve code writing by using advance select in ADOdb.

Simple Select

This is simple select in ADOdb


 include('adodb.inc.php'); # load code common to ADOdb 
    $conn = &ADONewConnection('access'); # create a connection 
    $conn->PConnect('northwind'); # connect to MS-Access, northwind DSN 

    $recordSet = &$conn->Execute('select * from products'); 

    if (!$recordSet) 
        print $conn->ErrorMsg(); 
    else 
        while (!$recordSet->EOF) { 
            print $recordSet->fields[0].' '.$recordSet->fields[1].'
'; $recordSet->MoveNext(); } $recordSet->Close(); # optional $conn->Close(); # optional

Select Limit

The formula is:


SelectLimit($sql,$numrows=-1,$offset=-1,$inputarr=false)

Returns a recordset if successful. Returns false otherwise. Performs a select statement, simulating PostgreSQL's SELECT statement, LIMIT $numrows OFFSET $offset clause.

For example


$connection->SelectLimit('SELECT * FROM TABLE',-1,10)

RecordCount()

Returns the number of rows in the record set. If the number of records returned cannot be determined from the database driver API, we will buffer all rows and return a count of the rows after all the records have been retrieved. This buffering can be disabled (for performance reasons) by setting the global variable $ADODB_COUNTRECS = false. When disabled, RecordCount( ) will return -1 for certain databases


 $rs = &$conn->Execute('select * from products');
 $total = $rs->RecordCount();


Series this article:
ADOdb: Introduction
ADOdb: Connection Statement
ADOdb: Advance Select Statement
ADOdb: How to show tables
ADOdb: How to show fields
ADOdb: How to show databases
ADOdb: Caching of Recordset
ADOdb: Recordset to HTML
ADOdb: Multi Database Connection
ADOdb: Data Dictionary
ADOdb: Quick Export Data
ADOdb: Insert data style
ADOdb: Replace Data
ADOdb: Log Query
PHP ADOdb: Understanding Pivot Table For Reporting
PHP ADOdb: Creating Pivot Table
PHP ADOdb: Creating Query to Build Pivot Table

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting