?
Solved

Query Return into a | Pipe delimited Document

Posted on 2014-09-14
2
Medium Priority
?
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1000 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …
Suggested Courses

777 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