phpeveryday.com

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


ADOdb: Quick Export Data

Tag: adodb, database, database layer   Category: PHP Database
post: 31 Oct 2007 read: 1,624


Export data to CSV (Comma Separated Value) and tab-delimited formats is one of cute fiture in ADOdb. You can add simple line code to produce data in csv. It will usefull if you want create backup feature in your application (without write complicated code).

Below for example:


<?php 
    include_once('toexport.inc.php'); 
    include_once('adodb.inc.php'); 

    $db = &NewADOConnection('mysql'); 
    $db->Connect($server, $userid, $password, $database); 
    $rs = $db->Execute('select fname as "First Name", 
surname as "Surname" from table'); 

    print "<pre>"; 
    print rs2csv($rs); 
 # return a string, CSV format 

    print '<hr>'; 
    $rs->MoveFirst(); 
# note, some databases do not support MoveFirst 

    print rs2tab($rs,false); 
# return a string, tab-delimited false == suppress field names in first line 

    print '<hr>'; 
    $rs->MoveFirst(); 
    rs2tabout($rs); 
# send to stdout directly (there is also an rs2csvout function) 
    print "</pre>"; 

    $rs->MoveFirst(); 
    $fp = fopen($path, "w"); 
    if ($fp) { 
        rs2csvfile($rs, $fp); 
# write to file (there is also an rs2tabfile function) 
        fclose($fp); 
    } 
?> 


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