PHP ADODB Export in CSV

From CoderLearner
Jump to: navigation, search

PHP ADODB CVS

Use rs2cvs to export the return records in comma-separated value (CVS) and tab-delimited formats.

Syntax ADODB rs2cvs

include 'adodb5/toexport.inc.php';
$table = 'user_infor';
$sql = "SELECT id,first_name,last_name,email FROM {$table} WHERE email IS NOT NULL";

$result = $conn1->Execute($sql);
print "<pre>";
print rs2csv($result); # return a string, CSV format
print '</pre>';

Example 1

<?php

include 'adodb5/adodb.inc.php';
include 'adodb5/toexport.inc.php';

$host = 'localhost';
$user = 'user2000';
$pass = 'password2000';
$dbname = 'w3cyberlearning';

$conn1 = &ADONewConnection('mysql');
$conn1->PConnect($host, $user, $pass, $dbname);
$table = 'user_infor';
$sql = "SELECT id,first_name,last_name,email FROM {$table} WHERE email IS NOT NULL";

$result = $conn1->Execute($sql);

if ($result == false) {
	print 'error' . $conn1->ErrorMsg() . '<br>';
}
print "<pre>";
print rs2csv($result); # return a string, CSV format
print '</pre>';


?>

Output

id,first_name,last_name,email
1,Paul,Mark,pm11@aa.com
2,Jam,Gill,jg11@aa.com
3,Mix,Alex,mlex11@aa.com
4,King,Mix,km11@aa.com