LOAD FILE access problem
am 26.02.2006 11:43:06 von CPDFrom PHP, doing a DROP TABLE and a CREATE TABLE is successful, but doing a
LOAD FILE keeps failing, with the error "Access denied for user
'db_user'@'localhost' (using password: YES)". The DROP/CREATE code and the
LOAD FILE code are in separate .php files which I am running from my
browser, but both commands are executed with mysql_query(). Don't know what
I'm doing wrong, so I would appreciate any help with this.
Both files run the following code first, which works fine:
==================================
// ------------------------------------------------------------ -----------
// Connect to MySQL server
// ------------------------------------------------------------ -----------
$link = mysql_connect($db_host, $db_user, $db_password);
if (! $link) {
die("Could not connect to {$db_user}/{$db_password} on host
{$db_host}:\n" .
mysql_error() . end_body_html());
exit(1);
}
else {
echo "Connected to MySQL on host {$db_host}.
\n";
}
// ------------------------------------------------------------ -----------
// Drop and create PHC_DB database
// ------------------------------------------------------------ -----------
$drop_db_query = "DROP DATABASE IF EXISTS {$db_name}";
if (run_mysql_query($drop_db_query));
$create_db_query = "CREATE DATABASE IF NOT EXISTS {$db_name}";
if (run_mysql_query($create_db_query));
// ------------------------------------------------------------ -----------
// Select database
// ------------------------------------------------------------ -----------
$db_selected = mysql_select_db($db_name, $link);
if (! $db_selected) {
die("Could not select {$db_name} database." .
mysql_error() . end_body_html());
exit(1);
}
else {
echo "Selected {$db_name} database.
\n";
}
==================================
Here is the section of DROP/CREATE code, which also works fine:
==================================
// ------------------------------------------------------------ -----------
// Drop and create REF_USER_LEVELS table
// ------------------------------------------------------------ -----------
$drop_table_query = "DROP TABLE IF EXISTS ref_user_levels";
run_mysql_query($drop_table_query);
$create_table_query = <<
user_level VARCHAR(10) NOT NULL,
actv_ind ENUM (
'A', -- active
'I' -- inactive
) NOT NULL,
max_counties INT(5),
description VARCHAR(100)
);
EOT;
run_mysql_query($create_table_query);
==================================
Now here is the LOAD FILE code, which fails with
"Error: Access denied for user 'db_user'@'localhost' (using password: YES)
LOAD DATA INFILE '/mysubdir/ref_user_levels.txt' INTO TABLE
ref_user_levels",
where db_user is the value of $db_user, and localhost is the value of
$db_host, as with the DROP/CREATE above.
$dat_file_path is based on DOCUMENT_ROOT, e.g., /mysubdir/
==================================
// ------------------------------------------------------------ -----------
// Populate REF_USER_LEVELS table
// ------------------------------------------------------------ -----------
$populate_table_query = "LOAD DATA INFILE
'{$dat_file_path}ref_user_levels.txt' INTO TABLE ref_user_levels";
run_mysql_query($populate_table_query);
==================================
Here are the support functions called:
==================================
function end_body_html() {
echo "\n