Skip to content

Instantly share code, notes, and snippets.

View jhqv's full-sized avatar

Janek Hellqvist jhqv

  • Sweden
View GitHub Profile
@paslandau
paslandau / mysql2csv
Last active February 15, 2024 16:27
Helper command to export data for an arbitrary mysql query into a CSV file.
#!/usr/bin/env php
<?php
$intro = <<<TEXT
Helper command to export data for an arbitrary mysql query into a CSV file.
Especially helpful if the use of "SELECT ... INTO OUTFILE" is not an option, e.g.
because the mysql server is running on a remote host.
Usage example:
./mysql2csv --file="/tmp/result.csv" --query='SELECT 1 as foo, 2 as bar;' --user="username" --password="password"
<?php
# hello
# this is pure crap, don't even think about using it
# it doesn't filter input vars or contain ANY error handling at all
# i wrote this while putting a kid to bed in, january 2016
# i repeat: do not use this script
# i am peder@earthpeople.se, a ceo - not a real developer
# prerequisites
# you need an account at mathem