我正在使用此查询创建mysql DB表的CSV

  $path = getcwd() . '/uploads/data.csv' ;

   $sql = "select email,username from `engine4_user` LIMIT 5000 into outfile '$path' FIELDS TERMINATED BY ','  LINES TERMINATED BY '\n' ";

但现在我需要一个额外的字段,即配置文件URL。它不存在于表中。所以我想用用户表的ID创建一个虚拟url列。比如https://mysiteurl/profile/$user\u id。
请帮忙。提前谢谢。

最佳答案

使用“CONCAT”运算符

$sql = "SELECT
        email,
        username,
        CONCAT('https://mysiteurl/profile/',user_id) as profile_url
        FROM `engine4_user`
        LIMIT 5000
        into outfile '$path' FIELDS TERMINATED BY ','  LINES TERMINATED BY '\n' ";

See example here

10-07 15:53