I am looking to write a MySQL query to a csv file.
At the minute I:
check for the original file, and delete it;
create a new (blank) file;
run the MySQL query and pass it into an array;
write it to the new file;
But it is missing something, as it only writes the first line from the query.
my code so far is:
Code: <?php
//Delete Original File
...
//Set variables
$uName = "root";
$pWord = "password";
$host = "localhost";
$Query = "[i]...MySQL query...[/i]";
$Filename = str_replace('.php', '', basename("Report")) . '_' . date("Ymdhis") . '.csv';
$ReportFiles = "c:ReportFiles\";
$Newfile = $ReportFiles.$Filename;
$cr = "n";
//Create a new (empty) file
echo exec("<nul (set/p z=) > "$Newfile"");
//Run MySQL Query
$connection = mysql_connect($host, $uName, $pWord) ;
mysql_select_db("dbName", $connection) ;
$result = mysql_query ($Query, $connection);
while ($row = mysql_fetch_array($result, MYSQL_NUM))
$String = implode(",",$row);
{
//Open file and save contents of query to that file
$fp = fopen($Newfile,"a");
if($fp){
fwrite($fp,$String.$cr);
fclose($fp);
echo "File saved successfully";
} else {
echo "Error saving file!";
}
}
?>
FTP Programs
Here is a list of commonly suggested FTP Programs to use:FileZillaSmartFTPCuteFTPRightFTPCoreFTPJFTPFireFTP
COOIS - Saving Object Overview WIP Status layouts
COOIS - Would like to be able to save the layout of an Object Overview - WIP Status report. There is currently NO icons for "choose layout" , "export" or "views" available while in Object Overview.
background color imagefill
HelloI would like to ask you why I see this square in red color just in my local xampp installation. If I run the code in the remote server (http://www.arreglaordenador.com/numberimage2.php) I see the
array_combine() trouble w/csv file
I have a problem with a piece of code I wrote to import some records from a csv file into mysql. I have a .csv file with about 300 records in it. The code worked perfect while testing on 3 or 4
Structure Question - One Table or One Table Per Record Set?
I have a web app (mySQL and PHP) which allows people to create an item with up to 200 records which I store in a single table. Any user subscribing to that item will be pulling up to 4 records from
Error when call dll from oracle
Hi all, please help me!
Passing PHP variables from one page to another
Hello-I'm having trouble figuring out how to transport a variable from one php file to another. Specifically, the name of an image, to be used as a subject in a form mail. I don't even really have the
IP question
ive got 2 ip addresses both global from same user how would i detect if they are local to each other
Connecion issue
Hi,For some reason, I keep getting this error when trying to connect:Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on...Warning: mysql_select_db()
problem with script manager
Hi iam using Net.2005.I have created ajax enabledwebsite.i have master page in which i have script manager.Ihavedifferent page in which iam trying to use ajax extension likeupdatepanel and update