Creating a file to be downloaded from server.

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
arcanebits
Veteran Member
Posts: 75
Joined: 2018-12-10 21:52

Creating a file to be downloaded from server.

Post by arcanebits » 2022-05-06 16:45

Hi, I have an Appgini app that is Is working quite nice and now I need to get some data out of the environment to work safe.
I need to make some “digging” into a DB, then to send that outcome of that to a txt or json to a txt file in the server that will be pulled with an another app.

Im more on the C# developing side and learning the APPGINI+/php/mysq ways and really enjoying it. Here is what I have in php

$sqlData = "SELECT * FROM Usuario INTO OUTFILE 'myoutput.txt'"; //ceate query
$resultData = $conn->query($sqlData); //créate the query execution
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); //create file
fwrite($myfile, $resultData); //write result of data gather
fclose($myfile); // close

this is not working. Any tip?
A3

arcanebits
Veteran Member
Posts: 75
Joined: 2018-12-10 21:52

Re: Creating a file to be downloaded from server.

Post by arcanebits » 2022-05-08 12:48

I do create a file via php, my issue is that i need to make a select and drop it lika a json...
anyone?

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 1514
Joined: 2018-04-01 10:12

Re: Creating a file to be downloaded from server.

Post by pböttcher » 2022-05-08 15:58

Hi,

from what I can see
$sqlData = "SELECT * FROM Usuario INTO OUTFILE 'myoutput.txt'"; //ceate query
$resultData = $conn->query($sqlData); //créate the query execution
will create a file myoutput.txt with the data from Usuario

But if that is not what you want, you need to change that a little bit:

Try:

Code: Select all

$sqlData = "SELECT * FROM Usuario'";
$res=sql($sqlData,$eo);
while ($row=db_fetch_assoc($res)) {
   $mydata[]=$row;
} 
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); //create file
fwrite($myfile, json_encode($mydata)); //write result of data gather
fclose($myfile); // close
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

arcanebits
Veteran Member
Posts: 75
Joined: 2018-12-10 21:52

Re: Creating a file to be downloaded from server.

Post by arcanebits » 2022-05-09 23:36

THANKS A LOT YOU SAVED ME tons of time
I coded a different solution but with a big caveat: TEXT FILE, anyhow I post the code here for anyone else who need to dump to text with a selected delimiter:
$resultData3 = $conn->query($sqlData3);
$delimitador = "\t";
while ($contador = $resultData3->fetch_assoc())
{
fwrite ($LogFile, join($delimitador, $contador) . "\n"); ---- Mi line
}
fclose($LogFile);

Your code helped me a lot since it throws the json file, it will be easier to handle in c#
I just added the JSON_PRETTY_PRINT to make it look cooler.
fwrite ($LogFile, json_encode($contador, JSON_PRETTY_PRINT)); //write result of data gather ----Your much helpful code!

See you all!
A3

Post Reply