Solved

Query Return into a | Pipe delimited Document

Posted on 2014-09-14
2
145 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

16 Experts available now in Live!

Get 1:1 Help Now