Exporting data from a MySQL table to a CSV file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
visionmaster
Forum Contributor
Posts: 139
Joined: Wed Jul 14, 2004 4:06 am

Exporting data from a MySQL table to a CSV file

Post by visionmaster »

Hello,

I want to export some data from a MySQL table to a CSV file using OUTFILE.

Code: Select all

<?php
include_once "modules/mod_datenbank.php";
$db = dbconnect();                                            
$query = mysql_query("SELECT idLink, dbLink
                        FROM links
                        WHERE dbFlag = '1'
                         INTO OUTFILE '/opt/lampp/htdocs/tarazi/phpcrawler/development/logfiles/data.txt'
                       FIELDS TERMINATED BY ','
                      LINES TERMINATED BY '\n' ") or die ("Ungültige Abfrage: " . mysql_error());
                                
$result = mysql_query($query);        

?>

Output:
--------
Unallowed Query: Access denied for user: 'pma@localhost' (Using password: YES)

Folder /logfiles has following rights drwxrwxrwx.

=> What is the error? How do I get it running?

Thanks
Vicious
Forum Contributor
Posts: 105
Joined: Fri Jun 20, 2003 12:40 pm

Post by Vicious »

chmodd folder and file to 777
visionmaster
Forum Contributor
Posts: 139
Joined: Wed Jul 14, 2004 4:06 am

Post by visionmaster »

Vicious wrote:chmodd folder and file to 777
I inserted following line before my query:

chmod ("/opt/lampp/htdocs/tarazi/phpcrawler/development/logfiles/", 755);

Output:
---------
Warning: chmod(): The operation is not allowed in in /opt/lampp/htdocs/tarazi/phpcrawler/development/export.php on line 13
Ungültige Abfrage: Access denied for user: 'pma@localhost' (Using password: YES)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

chmod it inside your ftp program, or from cpanel or what have you. Your mysql user may not have OUTFILE rights as well..
Post Reply