I'm trying to find a way to run this query in a custom drush command to dump chunks of data from the DB into CVS files.
The query works fine directly in the terminal but I was wondering how would you do it in code for Drupal 7? I guess I can transform a PHP array to a CVS file but wanted to know if Drupal has a way to write more complex queries like this :)
Big thanks in advance!
Query:
SELECT uid, name, mail INTO OUTFILE '/path/sqldumps/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM users
WHERE uid != 0
db_query()
will execute any arbitrary SQL string - are you having a problem using it or have you maybe not tried it yet? – Clive♦ Jun 17 '15 at 9:10