Jump to: navigation, search

PHP ADODB Export in CSV

From w3cyberlearnings

Contents

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,[email protected]
2,Jam,Gill,[email protected]
3,Mix,Alex,[email protected]
4,King,Mix,[email protected]


Related Links


Navigation
Web
SQL
MISC
References