Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
mysql dump into a text file

Posted by bschultz (bschultz), 17 September 2003
is there an easy way to dump a mysql db table into a text file, that is in a format suitable for reading?  (for example - one column per line...etc)

Posted by admin (Graham Ellis), 17 September 2003
You can select into outfile ...

select * from course into outfile "/tmp/fred.txt";

This will give you a tab delimited file, one row per row of  the table. Options are available to let you change the delimiter.  I suggest you give a full absolute path, or the output file will be dumped (I think) in the MySQL user's home directory.

If you want to transpose rows and columns, it's not straightforward - I read it that you want to do that, but perhaps I've misread the question?

Posted by bschultz (bschultz), 18 September 2003
using the following code...that didn't work right.  It put everything on the first "value", since it's tab delimited.  

Code:
<?php

$fp = @fopen("results.txt", "rb") or die("Couldn't open file");
@$data = fread($fp, filesize($fp));

while(!feof($fp))
{
$data .= fgets($fp);
}

fclose($fp);

$values = explode("\r\n", $data);

echo "$values[0]";
echo "$values[1]";

?>


I thought (obviously wrong!) that the

Code:
explode("\r\n", $data);


would put each value on a new line.  What am I doing wrong?

Posted by admin (Graham Ellis), 19 September 2003
You're reading the whole file with your fread, so there's nothing left for your while loop and fgets.  Have a look at the MySQL docs for the "into outfile" stuff too - there's options you can use to change separators and things ike that whihc might format the data better for your particular requirement.

Posted by bschultz (bschultz), 19 September 2003
thanks, Graham.  I was looking (without any luck) at the php.net docs.

Brian



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho