Location: PHPKode > scripts > rs2csv > rs2csv/readme.html
<html>
<head>
<title>rs2csv class</title>
</head>
<body>
<h4>rs2csv class version 1.0 by Sean Natoewal</h4>
<h1>Purpose</h1>
This class can be used to convert a resultset which has been generated by PHP's built-in MySQL functions to a comma separated values (CSV) file.
<h1>Examples</h1>
In the example files you should change the SQL-queries and the database connections to fit your needs.
<h1>Usage</h1>
<h3>To start we create a new instance of the rs2csv class</h3>
<small>
$csv = new rs2csv; // create a new instance of the rs2csv class.
</small>
<br><br>
<h3>Next set some properties for our CSV document. This is optional.</h3>
<small>
$csv->set_fname("example1.csv"); // Set the filename for download. Default is 'filename.csv'.<br>
$csv->set_ctype("application/octet-stream"); // Set the content-type for download. Default is 'text/tab-separated-values'.<br>
$csv->set_cdisp("attachment"); // Set the content-disposition for download. Default is 'attachment'.<br>
$csv->set_sep(";"); // Set the seperator sign. Default is ','.
</small>
<br><br>
<h3>Now we have several options. The usage will be explained for several situations.</h3>
<h4>Situation 1 / <a href="example1.php">Example 1</a></h4>
Let's say we don't have a database connection and we want to execute a SQL-query of which the results have to be exported to the CSV file.
<br><br>
<small>
$csv->make_con("server", "username", "password", "database_name"); // Open a database connection to the MySQL server.<br>
$csv->exec_sql("SELECT * FROM sometable"); // Execute your SQL-query.<br>
$csv->output_csv(); // Output the CSV file.
</small>
<br><br>
<h4>Situation 2 / <a href="example2.php">Example 2</a></h4>
Let's say we already have a database connection and we want to execute a SQL-query of which the results have to be exported to the CSV file.
<br><br>
<small>
$csv->exec_sql("SELECT * FROM sometable", $link); // Execute your SQL-query and if necessary supply the link_identifier of your database connection as a parameter.<br>
$csv->output_csv(); // Output the CSV file.
</small>
<br><br>
<h4>Situation 3 / <a href="example3.php">Example 3</a></h4>
Let's say we already have executed a SQL-query and the resultset has to be exported to the CSV file.<br><br>
<small>
$csv->process_rs($rs); // Process your resultset. Supply this resultset as a parameter.<br>
$csv->output_csv(); // Output the CSV file.
</small>
</body>
</html>
Return current item: rs2csv