From:             [EMAIL PROTECTED]
Operating system: windows2000
PHP version:      4.0.6
PHP Bug Type:     Output Control
Bug description:  PHP - MySQL select statement

Dear supporter,

My name is Thuyen Tran (KPMG CT Information) and I am working now with PHP
and MySQL.
I just have a problem when I try to read and write the data from the
database to the OUTFILE
using the following statement on the Unix web server:

$q_users = ("SELECT * INTO OUTFILE '$base_dir$csv_dir_name/$csv_file_users'
FROM user_info");

but unfortunetly this doesn't work. The following error occurs:

Database error: Invalid SQL: SELECT * INTO OUTFILE
'/space/web/kct/projects/testshop/export/outfile_users.csv' FROM
user_info
MySQL Error: 1 (Can't create/write to file
'/space/web/kct/projects/testshop/export/outfile_users.csv' (Errcode: 2))

It seem to me that the path '$base_dir$csv_dir_name'  
which is
"/space/web/kct/projects/testshop/export" as below can 
be seen, is not recognised (may be system drive??)
For the same code it works well for other web server. 
What I want to do is to put the *.csv file in a certain
specified directory.

I tried to open new file with success in the same directory as follows in
order to see what happens:

$fp = fopen("./hallo.txt", "w+"); // only try to test 

and also 
$q_users = ("SELECT * INTO OUTFILE './$csv_file_users'  FROM user_info
");

all of these work well.

So please could you tell me what was wrong?

Your quick response will graetly be appreciated. Many thanks!

Regards,
Thuyen


Here below is my code:

<?php
        //Create and make *.csv files to export
        //$base_dir     = "/space/web/kct/projects/testshop/";
        
        $csv_dir_name   = "export";
        $csv_file_orders        = "outfile_orders.csv"; 
        $csv_file_users = "outfile_users.csv";

        // open the directory with the path which is supplied as the sole
parameter
        chmod ("$base_dir", 0777);
        $dir = opendir(".");    
        $exist_flag = "false";  // the csv directory doesn't exist, need to create
one.
        
        while ($dir_name=readdir($dir)) {       
                if ($dir_name == $csv_dir_name){
                        $exist_flag = "true";                   
                        break;                  
                }
        }
        
        // create a new directory to store the *.csv file
        if ($exist_flag == "false") {
                mkdir("./$csv_dir_name", "");
                echo ("New sub directory '$base_dir$csv_dir_name' is created!");
        }

        // change permission for the created directory
        chmod ("./$csv_dir_name", 0777);
    
        // Set the current directory and open it
        chdir ("./$csv_dir_name");
        $dir = opendir(".");
 
        // Here just read all the 'entries' in it (both files and sub-folders)
        while ($file=readdir($dir)) {
                //echo("$file<BR>");    // only use to show all in the current 
directory
                
                // delete the csv file permanently if it exists.
                if ($file == $csv_file_users) {
                        unlink ($csv_file_users);
                }
                
                if ($file == $csv_file_orders) {
                        unlink ($csv_file_orders);
                }               
        }
        
         $fp = fopen("./hallo.txt", "w+"); // only try to test if it can, it
works.

        // Get all information of USERS and store them in *.csv file
        $q_users = ("SELECT * INTO OUTFILE
'$base_dir$csv_dir_name/$csv_file_users' FROM user_info");
        //$q_users = ("SELECT * INTO OUTFILE './$csv_file_users'  FROM
user_info "); it works.

        $db->query($q_users);
        $db->next_record();
        
?> 
-- 
Edit bug report at: http://bugs.php.net/?id=13382&edit=1


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to