Page 1 of 1

OUTFILE using PHP

Posted: Tue Dec 05, 2006 1:16 am
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

Posted: Tue Dec 05, 2006 1:27 am
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());

Posted: Tue Dec 05, 2006 1:37 am
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....

Posted: Tue Dec 05, 2006 2:06 am
by volka
Then you have to provide different credentials on your server?
madhu wrote:Please check the username and password.

Posted: Tue Dec 05, 2006 4:43 am
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

Posted: Tue Dec 05, 2006 5:46 am
by volka
Can you use the php ftp extension?