Location: PHPKode > scripts > Addressbook > addressbook/export-addressbook-csv.php
<?
// Make sure execution directory is "777"

include_once("config.php");
include_once("open-db.php"); 

// Connect database
$table="addressbook";

$result=mysql_query("select * from $table");

$out = '';

// Get all field names in the table".
$fields = mysql_list_fields($dbname,$table);

// Count the table fields and put the value into $columns.
$columns = mysql_num_fields($fields);

// Put the name of all fields to $out.
for ($i = 0; $i < $columns; $i++) {
$l=mysql_field_name($fields, $i);
$out .= '"'.$l.'",';
}
$out .="\n";

// Add all values in the table to $out.
while ($l = mysql_fetch_array($result)) {
for ($i = 0; $i < $columns; $i++) {
$out .='"'.$l["$i"].'",';
}
$out .="\n";
}

// Open file export.csv.
$f = fopen ('backup/export-addressbook'.date("Y-m-d-H").'.csv','w');

// Put all values from $out to export.csv.
fputs($f, $out);
fclose($f);

header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="backup/export-addressbook'.date("Y-m-d-H").'.csv"');
readfile('backup/export-addressbook'.date("Y-m-d-H").'.csv');
?>
Return current item: Addressbook