Database
  Home arrow Database arrow Page 12 - Accessing Databases with ADODB
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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? 
DATABASE

Accessing Databases with ADODB
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 37
    2004-08-02

    Table of Contents:
  • Accessing Databases with ADODB
  • Connecting, Queries and Quoting
  • Introducing Record Sets
  • Retrieving Multiple Rows
  • Understanding Error Handling
  • Generating HTML
  • More HTML Generation
  • Printing
  • Splitting Data Across Multiple Pages
  • Pivot Tables
  • Caching
  • Exporting Data

  • 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


    Accessing Databases with ADODB - Exporting Data


    (Page 12 of 12 )

    The toexport.inc.php file defines some functions that export record sets as tab-delimited or Comma-Separated Value (CSV ) data. The rs2csv() function returns a string containing the record set as a series of CSV lines:

    $rs = $conn->Execute('SELECT * FROM ice_cream');
    $csv = rs2csv($rs);

    The rs2tab() function returns a string containing the record set as a series of lines with tab-delimited values:

    Accessing Databases with ADODB

    $rs = $conn->Execute('SELECT * FROM ice_cream');
    $csv = rs2tab($rs);

    Both functions escape double quotes by doubling them. A double quote mark in a value is turned into "" in the output. Fields with double quotes in them are also surrounded by double quotes. The rs2csv() function also surrounds fields that contain commas with double quotes.

    There are also versions of these functions that save the CSV or tab-delimited data directly to a file, called rs2csvfile() and rs2tabfile(). These functions should be passed a file handle as a second argument:

    if ($fh = fopen('/tmp/ice_cream.csv','w')) {
         $rs = $conn->Execute('SELECT * FROM ice_cream');
         rs2csvfile($rs,$fh);
         fclose($fh);
    } else {
         print "Can't open /tmp/ice_cream.csv";
    }

    Additionally, there are versions of rs2csv() and rs2tab() that print the exported string rather than returning it. They are called rs2csvout() and rs2tabout():

    $rs = $conn->Execute('SELECT * FROM ice_cream');
    rs2tabout($rs);

    Aside from the conversion of double quotes in values, all six export functions convert newlines in values to spaces in output. They also include a title line consisting of the column names in the record set. To suppress the title line, pass false as a last argument to any of the functions.

    This is from Essential PHP Tools, by David Sklar (Apress, ISBN 1590592808). Check it out at your favorite bookstore today. Buy this book now.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · i want the programming code for the add delete update useing the adodb ontrols.
     

    DATABASE ARTICLES

    - Excel Reference
    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




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