Ishaque Javed
Ishaque Javed

Reputation: 313

how to add custom column in db table when using 'into outfile' query

I am using this query to create CSV of my mysql DB table

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

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

But now I need one extra field that is profile url .which doesn't exists on the table. So i wanna create a virtual url column using the ID of that user table. Like https://mysiteurl/profile/$user_id .

Please help. Thanks in advance.

Upvotes: 1

Views: 40

Answers (1)

Ima
Ima

Reputation: 1109

Use "CONCAT" operator

$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

Upvotes: 1

Related Questions