Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL export to Fixed-Width (.prn?) file

Status
Not open for further replies.
Oct 15, 2003
2
US
Does anybody know if MySQL can natively export to a fixed-width format? I have tried "mysqldump" and also "SELECT * INTO OUTFILE", but both of these methods add undesirable "tab" spaces into the export.

I have specified column lengths for the table during creation, so that should not be an issue.

I know this is possible, as I have done it via a 3rd party utility called MYSQLyog, but I need to be able to do this from a PHP script, or at the very least from the MySQL prompt.

Help?

- ZelloFellow
 
Thanks, Sleipner...Could you point me in the direction of the PHP functionality to accomplish this? I have been looking into this for a couple of days now with no success, and finally gave in and came to the forum to ask for help.

%-)
 
There's not much to it.

Connect to MySQL, select the appropriate database, then pass the SELECT query to the database server. (Take a look at the sample code here:
I would then open the output file and loop through the returned data from the query, writing the records in fixed form to the file (See sample code:
Want the best answers? Ask the best questions: TANSTAAFL!!
 
Less elegant than sleipnir solution but for a one off try

select into outfile where you specify fields terminated by ''

but you will have to tediously prepare all of your variables with something like RPAD(str,len,padstr) to get them to always output as a fixed length
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top