Thanks the community I was able to create a script that enable me to export data from a database table into a csv file.
"Article ID",Shoppergroupname,"Promotion Price",VAT-Code,"Article Currency","Promotion Start Date","Promotion End Date"
10192605,"Aucun Groupe Clients",2.86,2,27,07.01.2010,30.12.2999
10192689,"Aucun Groupe Clients",3.33,2,27,07.01.2010,30.12.2999
10193415,"Aucun Groupe Clients",2.40,1,27,07.01.2010,30.12.2999
10193431,"Aucun Groupe Clients",7.83,1,27,07.01.2010,30.12.2999
I would like my data being exported without quotes enclosure and values|fields being separated with ;
instead of ,
.
I would appreciate if someone could advise me how to achieve this.
Thanks a lot in advance.
Cheers,
Marc
My script is the following :
// Create connection
$conn = new mysqli($databasehost, $databaseusername, $databasepassword, $databasename);
// Check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
echo "Connected successfully | ";
// Create filename
date_default_timezone_set('Europe/Zurich');
$today = date("Y-m-d-G-i-s");
$csvname = "WS_PRICE_IMPORT_".$today.".csv";
$csvfullname = '/var/.../'.$csvname;
// Create a file pointer connected to the output stream
$output = fopen($csvfullname, 'w');
// Output the column headings
fputcsv($output, array('Article ID', 'Shoppergroupname', 'Promotion Price', 'VAT-Code', 'Article Currency', 'Promotion Start Date', 'Promotion End Date'));
// Fetch the data
$sql = "SELECT `Article ID`, `Shoppergroupname`, `Promotion Price`, `VAT-Code`, `Article Currency`, `Promotion Start Date`, `Promotion End Date` FROM jos_temppriceimport";
$result = $conn->query($sql);
if (!$result) {
echo "Unable to execute query in the database : " . mysql_error();
exit;
}
if ($result->num_rows == 0) {
echo "No record found, no record to export in CSV.";
exit;
}
// Loop over the rows, outputting them
while ($row = $result->fetch_row()) fputcsv($output, $row);