PHP Classes

File: example3.php

Recommend this page to a friend!
  Classes of Sean Natoewal  >  rs2csv  >  example3.php  >  Download  
File: example3.php
Role: Example script
Content type: text/plain
Description: Example script 3
Class: rs2csv
Convert a MySQL record set to a CSV file.
Author: By
Last change:
Date: 13 years ago
Size: 905 bytes


Class file image Download
Example 3
// Make your own database connection to the MySQL server and execute your SQL-query.
$link = mysql_connect("localhost", "root", "") or die("Could not connect : " . mysql_error());
mysql_select_db("mysql", $link) or die("Could not select database");
$rs = mysql_query("SELECT * FROM user");

$csv = new rs2csv; // create a new instance of the rs2csv class.
$csv->set_fname("example3.csv"); // Set the filename for download. Default is 'filename.csv'.
$csv->set_ctype("application/octet-stream"); // Set the content-type for download. Default is 'text/tab-separated-values'.
$csv->set_cdisp("attachment"); // Set the content-disposition for download. Default is 'attachment'.
$csv->set_sep(";"); // Set the seperator sign. Default is ','.
$csv->process_rs($rs); // Process your resultset.
$csv->output_csv(); // Output the CSV file.