简体   繁体   中英

Exporting data mysql database using php

I am able to export data from a mysql database into a csv file. It is working if i write /save/to/file but I want file to be saved to where the customer decides. In a previous php the customer enters the directory where they want the csv exported to. This variable is called $pathway. Therefore, in the table information is stored such as username and pathway. I want the csv to be exported based on the username (eg if username= Bob, export to $pathway). I cannot import this variable into the export.php. Where is says $sql = "SELECT * INTO OUTFILE '??????' I need to add the variable $pathway but i am not sure how to do it.

if (!$connection) {
die("Database server connection failed.");
die(mysqli_error($db));
} else {

//Attempt to select the database
$dbconnect = mysqli_select_db($connection, $db);
//Check to see if we could select the database

if (!$dbconnect) {
    die("Unable to connect to the specified database!");
} else {
    $sql = "SELECT * INTO OUTFILE '??????'
FIELDS TERMINATED BY '\t' 
LINES TERMINATED BY '\r\n' 
FROM tablename;"

You should try like :

SELECT *
FROM tablename
INTO OUTFILE 'CSV_LOCATION'
FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"'
LINES TERMINATED BY '\r\n';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM