I use the following code to write a .csv file from my MySQL database and it works just fin when the db is on my local PC. When I upload everything to the live server I do not get a local copy.
How do I modify my code to get the .csv file created on the live server saved on local PC?
Thanking you in advance for your help.
My code:
$contactsList = @mysql_query("SELECT * FROM contact, location
WHERE contact.mailLocID = location.locID
ORDER BY familyName, firstName");
if (!$contactsList) {
exit('<p>Error retrieving contacts from database<br />' . 'Error: ' . mysql_error() . '</p>');
}
// Get first row of output
$contact = mysql_fetch_assoc($contactsList);
// Built an array of field names
foreach ($contact as $fieldname => $value)
{
$fieldnames[] = $fieldname;
}
// Output to the file
fputcsv($file, $fieldnames, ",", "\"");
// Reset the pointer
mysql_data_seek($contactsList, 0);
// Output the data to the file
while ($contact = mysql_fetch_assoc($contactsList))
{
fputcsv($file, $contact, ",", "\"");
}
fclose($file);
...
How do I modify my code to get the .csv file created on the live server saved on local PC?
Thanking you in advance for your help.
My code:
$contactsList = @mysql_query("SELECT * FROM contact, location
WHERE contact.mailLocID = location.locID
ORDER BY familyName, firstName");
if (!$contactsList) {
exit('<p>Error retrieving contacts from database<br />' . 'Error: ' . mysql_error() . '</p>');
}
// Get first row of output
$contact = mysql_fetch_assoc($contactsList);
// Built an array of field names
foreach ($contact as $fieldname => $value)
{
$fieldnames[] = $fieldname;
}
// Output to the file
fputcsv($file, $fieldnames, ",", "\"");
// Reset the pointer
mysql_data_seek($contactsList, 0);
// Output the data to the file
while ($contact = mysql_fetch_assoc($contactsList))
{
fputcsv($file, $contact, ",", "\"");
}
fclose($file);
...