Hi everyone,
A code that contains 2 quries: first one lists hours made for a company (company1) and second: total of those hours, writes the results in a csv file goes like this:
<?php
// Connect to database server
$con=mysqli_connect("localhost","root","root","db");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql1 = "SELECT startDate,endDate,intervalTime, institution, company
INTO OUTFILE 'd:/companies/xxx.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\
'
FROM june2013
WHERE company='company1'";
$sql2 = "SELECT company, SEC_TO_TIME(SUM(TIME_TO_SEC(intervalTime)))
INTO OUTFILE 'd:/companies/xxx.csv'
FIELDS TERMINATED BY ','
FROM june2013 GROUP BY company
WHERE COMPANY='company1'";
if (mysqli_query($con,$sql1))
{
echo "List added to text file successfully";
}
else
{
echo "Error transferring list " . mysqli_error($con);
}
if (mysqli_query($con,$sql2))
{
echo "Summary added to text file successfully";
}
else
{
echo "Error transferring summary " . mysqli_error($con);
}
mysqli_close($con);
?>
If I run 1 query only (just sql1 for example), it goes well. If I add a second query (sql2) I get an error message that says:
Error transferring summary File ‘d:/companies/xxx.csv’ already existsError transferring summary
Is there a way to send 2 queries’ results to a csv file?
Thanks a lot!