Login | Register | FAQ
Anonymous

mysql: can't find result of a query (into text file)

+ Post a reply

Page 1 of 1


mysql: can't find result of a query (into text file)

by pssheba » Wed Jul 31, 2013 10:01 am

Hi everyone,
I need the results of a mysql query to be piped unto a text file so i can print it. Problen is: Where is
the text file ?! Here is the php code to run the query:
Code: Select all
<?php
// Connect to database server
$con=mysqli_connect("localhost","root","root","mydb");
if (mysqli_connect_errno())
    {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
$sql1 = "SELECT startDate,endDate,intervalTime FROM june2013
    INTO OUTFILE 'xxx.txt'";
if (mysqli_query($con,$sql1))
    {
     echo "Data added to text file successfully";
    }
else
   {
    echo "Error transfering data " . mysqli_error($con);
    }
  mysqli_close($con);
?>

After I had ran the above code I recieved the message:
Data added to text file successfully

Which means the code succeeded in creating the desired text file.
I searched the file in my HD at: xampp/htdocs and couldn't find it ! Then I made a WINDOWS 7 search for
"xxx.txt" and the search found nothing !
So I ran again the code and recieved an error message that says:
Error transfering data File 'xxx.txt' already exists

If that file exixts, where could it exist if not on my hard disk? If it is on my hard disk why can't I find it?
Could it be some kind of a "hidden file"?
Can anyone help me with that?
Thanks
User avatar

pssheba

  • Posts: 8
  • Joined: Sat Jul 27, 2013 12:09 pm

Re: mysql: can't find result of a query (into text file)

by stonelee » Wed Jul 31, 2013 11:30 am

pssheba wrote:Hi everyone,
I need the results of a mysql query to be piped unto a text file so i can print it. Problen is: Where is
the text file ?! Here is the php code to run the query:
Code: Select all
<?php
// Connect to database server
$con=mysqli_connect("localhost","root","root","mydb");
if (mysqli_connect_errno())
    {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
$sql1 = "SELECT startDate,endDate,intervalTime FROM june2013
    INTO OUTFILE 'xxx.txt'";
if (mysqli_query($con,$sql1))
    {
     echo "Data added to text file successfully";
    }
else
   {
    echo "Error transfering data " . mysqli_error($con);
    }
  mysqli_close($con);
?>

After I had ran the above code I recieved the message:
Data added to text file successfully

Which means the code succeeded in creating the desired text file.
I searched the file in my HD at: xampp/htdocs and couldn't find it ! Then I made a WINDOWS 7 search for
"xxx.txt" and the search found nothing !
So I ran again the code and recieved an error message that says:
Error transfering data File 'xxx.txt' already exists

If that file exixts, where could it exist if not on my hard disk? If it is on my hard disk why can't I find it?
Could it be some kind of a "hidden file"?
Can anyone help me with that?
Thanks


When you run the code it'll create a file in "[PATH_OF_PHP_SERVER_PROGRAMME]\Mysql\data\june2013\xxx.txt"

Ex :

I'm using vertrigo, so my path is : F:\WORK\PHP\VertrigoServ\Mysql\data\june2013\3\xxx.txt


Hope this help !
User avatar

stonelee

  • Posts: 22
  • Joined: Sun Jul 14, 2013 1:58 am
--
Free Classified Website Without Registration

Re: mysql: can't find result of a query (into text file)

by XainPro » Wed Jul 31, 2013 11:57 am

i think that's not the correct way to output the data into text file you should used

any I/O method e.g

<?php
echo file_put_contents("test.txt","Hello World. Testing! or your query out put string ");
?>
User avatar

XainPro

  • Posts: 2401
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: mysql: can't find result of a query (into text file)

by pssheba » Thu Aug 01, 2013 12:06 pm

Thanks a lot. It worked !
User avatar

pssheba

  • Posts: 8
  • Joined: Sat Jul 27, 2013 12:09 pm


+ Post a reply

Page 1 of 1