Bug #13382 Updated: PHP - MySQL select statement
| From: | sander@php.net | Date: | Fri, 19 Oct 2001 15:07:35 +0000 |
| Subject: | Bug #13382 Updated: PHP - MySQL select statement | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-68414@lists.php.net to get a copy of this message | ||
ID: 13382
Updated by: sander
Reported By: tranxuan.thuyen@kpmg-ct.com
Old Status: Open
Status: Bogus
Bug Type: Output Control
Operating System: windows2000
PHP Version: 4.0.6
New Comment:
This is unlikely to be a bug in PHP.
Check your permissions; probably MySQL has no permission to write there.
Ask further support questions on the appropriate mailinglist (see http://www.php.net/support.php).
Previous Comments:
------------------------------------------------------------------------
[2001-09-21 16:27:59] tranxuan.thuyen@kpmg-ct.com
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 this bug report at http://bugs.php.net/?id=13382&edit=1