php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13382 PHP - MySQL select statement
Submitted: 2001-09-21 16:27 UTC Modified: 2001-10-19 11:07 UTC
From: tranxuan dot thuyen at kpmg-ct dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.0.6 OS: windows2000
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tranxuan dot thuyen at kpmg-ct dot com
New email:
PHP Version: OS:

 

 [2001-09-21 16:27 UTC] tranxuan dot thuyen at kpmg-ct dot 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();
	
?> 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-19 11:07 UTC] sander@php.net
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).
 [2004-06-09 04:27 UTC] asdfsaf at asdfasf dot com
asdfasf
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 04:01:29 2024 UTC