Created
November 18, 2018 12:57
-
-
Save klebinhopk/41d87f1aff15059869718e09730b335a to your computer and use it in GitHub Desktop.
MYSQL, EXPORT CSV: Export to csv straight from MySQL - note MySQL may not have permission to write this file to your app directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$app_directory = dirname(BASEPATH); | |
$export_location = $app_directory . '/assets/exports/'; | |
$filename = "export-" . date('Y-m-d H-i-s') . ".csv"; | |
$export_location = $export_location . $filename; | |
$query = $this->db->query(" | |
SELECT users.id, users.firstname, users.lastname, users.email, users.dob, messages.line1, messages.line2, messages.line3, messages.barcode_selected, address.my_address, address.firstname, address.lastname, address.address1, address.address2, address.town, address.postcode, address.datecreated | |
FROM users | |
JOIN messages | |
ON users.id = messages.user_id | |
JOIN address | |
ON users.id = address.user_id | |
INTO OUTFILE '$export_location' | |
FIELDS TERMINATED BY ',' | |
LINES TERMINATED BY '\r\n' | |
"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment