php - export table data in csv formate and store in folder -


how in php ?

i wan't export table data in csv file , store csv file in backup folder.

for using :

$query = "select * `login_details`"; $file_name = "login_details"; $sql_csv = mysql_query($query) or die("error: " . mysql_error()); //replace line appropriate db abstraction layer  header("content-type:text/octect-stream"); $done = header("content-disposition:attachment;filename=$filename");  while($row = mysql_fetch_row($sql_csv)) {      print '"' . stripslashes(implode('","',$row)) . "\"\n"; } 

thanks.

you must open file write (handle) use http://php.net/manual/en/function.fopen.php

use created handle write string http://php.net/manual/en/function.fputcsv.php

close handle when done(see doc fopen) use fclose()

for example:

//you code data sql $handle = fopen('full path store (you can use ftp etd)', 'w'); // see mode while($row = mysql_fetch_row($sql_csv)) {      fputcsv($handle, $row); } fclose($handle); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -