OUTFILE using PHP

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
madhu
Forum Commoner
Posts: 82
Joined: Fri Mar 03, 2006 9:34 am

OUTFILE using PHP

Post by madhu »

Hi all,

Am trying to export data from a TABLE named 'registration' to a csv file 'madhu.csv'.

i used the following program to do that:

Code: Select all

<?
include("inc.php");  //contains hostname,username,pwd
$db = mysql_connect($my_server,$my_user,$my_pass) or die("Unable to connect to MySQL");
mysql_select_db($data_base) or die("failed opening database");
$select = "SELECT * INTO OUTFILE 'D:/webserver_files/SV/madhu.csv'
           FIELDS TERMINATED BY ','
           LINES TERMINATED BY '\n'
           FROM registration";
$result = mysql_query($select);
?>
It is working in local but it is not working in server.

Please suggest me how to solve this..............

Thanks and regards
MADHU
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

"not working" means exactly what?
Maybe the mysql server wants to tell you something

Code: Select all

$result = mysql_query($select) or die(mysql_error());
madhu
Forum Commoner
Posts: 82
Joined: Fri Mar 03, 2006 9:34 am

Post by madhu »

When i try to run in server databse, it gave the following error:

SQL execution error # 1045.Response from database:
Access denied for user 'username'@'%'(using password:YES)
Please check the username and password.
Afterwards,please ask the database administrator (Internet provider) if you are allowed to connect from this computer.


But in local database it is working....
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Then you have to provide different credentials on your server?
madhu wrote:Please check the username and password.
madhu
Forum Commoner
Posts: 82
Joined: Fri Mar 03, 2006 9:34 am

Post by madhu »

Hi now am able to upload the content from a table into a file as .csv format using the following code:


Code: Select all

<?
//DATABASE CONNECTION
include("inc.php"); //contains database details
$db = mysql_connect($my_server,$my_user,$my_pass) or die("Unable to connect to MySQL");
mysql_select_db($data_base) or die("failed opening database");
$result = mysql_query("select * from tablename");
//FETCH THE RECORDS AND WRITE TO CSV FILE
unlink("madhu.csv");
$fp = fopen("madhu.csv", "a");
fwrite($fp, "PAGEDATE, STATUS, EDITIONID, PUBLISHTYPE, PUBLISHBY\n");
while($row = mysql_fetch_array($result)){
      fwrite($fp, "$row[page_date], $row[status], $row[edition_id], $row[publish_type], $row[publish_by]\n");
     }
fclose($fp);
?>
Now this file(madhu.csv) i created in one server(FTP).

Now am trying to transfer this madhu.csv file to another server(FTP) through programatically.....

Please suggest me how to solve this issue.

If i got the solution for this,then i will post the code.

Waiting for your valuable and positive replies....

Thanks and regards
MADHU
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Can you use the php ftp extension?
Post Reply