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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度