Solved

Query Return into a | Pipe delimited Document

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

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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

726 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