简体   繁体   English

使用PHP导出数据MySQL数据库

[英]Exporting data mysql database using php

I am able to export data from a mysql database into a csv file. 我能够将数据从mysql数据库导出到csv文件中。 It is working if i write /save/to/file but I want file to be saved to where the customer decides. 如果我将/ save / to / file写入,但我希望将文件保存到客户决定的位置,则可以正常工作。 In a previous php the customer enters the directory where they want the csv exported to. 在以前的php中,客户输入他们要将csv导出到的目录。 This variable is called $pathway. 此变量称为$ 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). 我希望根据用户名导出csv(例如,如果用户名= Bob,则导出到$ pathway)。 I cannot import this variable into the export.php. 我无法将此变量导入到export.php中。 Where is says $sql = "SELECT * INTO OUTFILE '??????' 哪里说$ sql =“ SELECT * INTO OUTFILE'??????' I need to add the variable $pathway but i am not sure how to do it. 我需要添加变量$ pathway,但是我不确定该怎么做。

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';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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