>I use phpMyAdmin which enables me to take dump of >mySQL Table Data into Comma Seperated Values file >(.csv) > >Now, i have to create such a program that accomplishes >this, without using phpMyAdmin. Can someone guide me >to this procedure..
Since PHP has a fget_csv function (or something like that) odds are pretty good it can write CSV as well. If not, and *IF* you can do tab-delimited instead (*MUCH* easier) and just as easy to suck in on the other end, you can do: <?php require 'connect.inc'; $query = "select * from mytable"; $rows = mysql_query($query, $connection) or error_log(mysql_error()); while ($row = msyql_fetch_row($rows)){ $tab_delimited = implode("\t", $row); echo $tab_delimited, "\n"; // Or you can write to a file, or whatever. } ?> If you *MUST* use CSV, not tab-delimited, I *THINK* this will work: <?php require 'connect.inc'; $query = 'select * from mytable'; $rows = mysql_query($query, $connection) or error_log(mysql_error()); while ($row = mysql_fetch_row($rows)){ while (list(,$value) = $row){ if (strstr($value, ',') || strstr($value, '"')){ $value = str_replace('"', '""', $value); $value = str_replace(',', '",', $value); $value = "\"$value\""; $output_row[] = $value; } echo implode(',', $output_row), "\n"; } } ?> -- Like Music? http://l-i-e.com/artists.htm Off-Topic: What is the moral equivalent of 'cat' in Windows? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php