Jump to content

Another issue I cant figure with fputcsv


Go to solution Solved by alanl1,

Recommended Posts

Hi All

 

I have been writing my DB values to a csv without any problems until now.

 

When I extract a date field it does not write to the file.  Please find below the code that works and the code that does not work

 

 

working

 

while($row = sqlsrv_fetch_array($exportquery1))
{
 
 fputcsv($handle, array($row['businessunit'],$row['costcentre']));
}
// Finish writing the file
fclose($handle);

 

not working

 

 

while($row = sqlsrv_fetch_array($exportquery1))
{
 
 fputcsv($handle, array($row['businessunit'],$row['costcentre'],$row['Tdate]));
}
// Finish writing the file
fclose($handle);

 

any ideas what I would need to do, when I query within the backend database it is fine

sorry yes that code should be there that is just a copy and past error when I was showing example.  it should be

 

 

 fputcsv($handle, array($row['businessunit'],$row['costcentre'],$row['Tdate']));

 

do you think it could be something to do with the quotes with the dat conversion?

 

regards
 

is that the exact spelling and capitalization of your database column name? are you selecting that column in your query statement? do you have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying the errors it detects?

  • Solution

I have managed to get this to display by doing amending the column in the DB to date and also changing the query to

 

 

CONVERT(varchar, DATEPART(dd, Tdate)) + '/' +
  CONVERT(varchar, DATEPART(mm, Tdate)) + '/' +
  CONVERT(varchar, DATEPART(yyyy, Tdate)) as Tdate

 

just one question, how do i actually set error_reporting set to E_ALL and display_errors set to ON so that php will help me in displaying the errors it detects?
 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.