PHP
  Home arrow PHP arrow Page 7 - PHP Application Development With ADODB...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP Application Development With ADODB (part 1)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2002-07-24

    Table of Contents:
  • PHP Application Development With ADODB (part 1)
  • A Little Insulation
  • The Bookworm Turns
  • Anatomy Class
  • Different Strokes
  • Getting It All
  • Playing The Field
  • Strange Relationships
  • Hitting The Limit
  • Coming Soon, To A Screen Near You

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PHP Application Development With ADODB (part 1) - Playing The Field


    (Page 7 of 10 )

    ADODB comes with a number of utility functions that provide you with useful information on the query you just executed. The most useful of these are the RecordCount() and FieldCount() methods, which return the number of rows and columns in the recordset respectively. Here's a simple example, which demonstrates:

    <?php // uncomment this to see plaintext output in your browser // header("Content-Type: text/plain"); // include the ADODB library include("adodb.inc.php"); // create an object instance // configure library for a MySQL connection $db = NewADOConnection("mysql"); // open connection to database $db->Connect("localhost", "john", "doe", "db278") or die("Unable to connect!"); // execute query $query = "SELECT * FROM library"; $result = $db->Execute($query) or die("Error in query: $query. " . $db->ErrorMsg()); // get and print number of rows in resultset echo $result->RecordCount() . " rows returned\n"; // get and print number of fields in resultset echo $result->FieldCount() . " fields returned\n"; // clean up $db->Close(); ?>
    You can obtain further information on each field with the FetchField() method, which returns an object containing detailed information on the field properties, including its name and type. Consider the following variant of the example above, which might make this a little clearer:

    <?php // uncomment this to see plaintext output in your browser // header("Content-Type: text/plain"); // include the ADODB library include("adodb.inc.php"); // create an object instance // configure library for a MySQL connection $db = NewADOConnection("mysql"); // open connection to database $db->Connect("localhost", "john", "doe", "db278") or die("Unable to connect!"); // execute query $query = "SELECT * FROM library"; $result = $db->Execute($query) or die("Error in query: $query. " . $db->ErrorMsg()); // get field information for($x=0; $x<$result->FieldCount(); $x++) { print_r($result->FetchField($x)); } // clean up $db->Close(); ?>
    Here's what the output might look like for the "id" field:

    stdClass Object ( [name] => id [table] => library [def] => [max_length] => 3 [not_null] => 1 [primary_key] => 1 [multiple_key] => 0 [unique_key] => 0 [numeric] => 1 [blob] => 0 [type] => int [unsigned] => 1 [zerofill] => 0 [binary] => )

    More PHP Articles
    More By icarus, (c) Melonfire


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT