doubao6681 2015-06-23 11:26
浏览 93

使用php导出数据mysql数据库

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 (e.g. 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 '
' 
FROM tablename;"
  • 写回答

1条回答 默认 最新

  • drug95107 2015-06-23 12:15
    关注

    You should try like :

    SELECT *
    FROM tablename
    INTO OUTFILE 'CSV_LOCATION'
    FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"'
    LINES TERMINATED BY '
    ';
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料