Solved

Query Return into a | Pipe delimited Document

Posted on 2014-09-14
2
146 Views
Last Modified: 2014-09-30
How do I write a MySql Query (PDO) and then save the return as a .TXT File and have each return be Pipe delimited?  I know this question is broad but I have to start some place.
0
Comment
Question by:rgranlund
2 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 40322019
This article shows how to use PDO.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

The way I would think you want to get pipe-delimited data would be row-by-row.  To do that retrieve the results set in the form of an array of arrays (that's pretty much standard return for PDO).  Then iterate over the arrays to get each row of the results set.  You can use implode('|', $row) to create a pipe-delimited string and you can write that into the .txt file with fputs().  Or you can use fputcsv() and provide a delimiter character.
0
 
LVL 7

Assisted Solution

by:Vimal DM
Vimal DM earned 250 total points
ID: 40323049
Hi,

Use this build-in mysql function for exporting data into TXT file, giving you a sample mysql query for it...

mysql> SELECT * FROM passwd INTO OUTFILE '/tmp/tutorials.txt'
    -> FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    -> LINES TERMINATED BY '\r\n';
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now