[SLUG] exporting mysql to excel file

Ian Eade at IGM Web Design ieade at igmwebdesign.info
Tue Feb 4 21:34:01 GMT 2003


One way is to use PHP to extract the data from MySQL and create a comma
delimited file, then get Excel to import file,
maybe there is a specific file or other but something like this would work


Ian




<?php
$path = '/full/path/to/text/file/';
$file = 'excel_dump.txt';
$page = $path.$file;
$delimiter = '|';

$G_DB   = "";	# database name
$G_HOST = "";     # hostname
$G_PORT = "";	# mysql port
$G_USER = "";     # mysql username
$G_PASS = "";     # mysql password

$db	= mysql_pconnect($G_HOST.":".$G_PORT,$G_USER,$G_PASS);
@mysql_select_db($G_DB) or die("Unable to connect to database ");

$sql = "
SELECT *
FROM [table name]
WHERE [condition]
";

if($results = mysql_query($sql, $db))
{

while($details = mysql_fetch_array($results))
{
// write the values delimited by a pipe
$content = $details[column1].$delimeter.$details[column2];

$fp = fopen("$page", "a");  	// Open a file pointer, a = append
fputs($fp, $content);       	// Write the value of $content to
excel_dump.txt
fclose($fp); 			// Close the file pointer

}
}
?>










-----Original Message-----
From: scarborough-admin at mailman.lug.org.uk
[mailto:scarborough-admin at mailman.lug.org.uk]On Behalf Of Phil Kershaw
Sent: Tuesday, February 04, 2003 07:54
To: scarborough at mailman.lug.org.uk
Subject: [SLUG] exporting mysql to excel file


Hi Folks,

I hope to make the 20th all being well. I'll bring a laptop with mandrake on
if it helps.

Can anyone recommend a utility to export a mysql database to excel. I have a
mysql database running on the server and want export the data to excel
format for use on windows machines.


Regards

Phil Kershaw






More information about the Scarborough mailing list