Possible privileges issue involving PHP and MySQL
Posted by: havelly (---.dyn.iinet.net.au)
Date: September 28, 2015 03:58AM

Hello Riggs

1. XP 32 bit
2. WampServer ver 2.4
3. Apache ver 2.4.4
4. PHP ver 5.4.16
5. MySQL ver 5.6.12
6. WampServer icon is green
8. Have access to localhost
9. Do not have access to phpMyAdmin
11. Anti-virus - AVG
Firewall - Symantec
12. Installation path - c:\wamp

I have been happily using WampServer until recently. With a project I am involved with a PHP command was used to produce a backup file of a MySQL table. The actual command used was:

SELECT * INTO OUTFILE 'backupDB.txt' FROM table_name;

When this command was entered at the command line there was no problem - the file backupDB.txt was generated.

When the command was included in a PHP file it did not work and the following error message was given:

1045: Access denied for user 'mysql -u root'@'localhost' (using password: NO)

This seems to be indicating that the user does not have the rights to create a file on the server host.

I have searched high and low for a fix to this problem in programming forums to no avail.

Are you able to shed any light on the workings of WampServer as far as I am aware I have admin rights (can not access phpMyAdmin to confirm that). That being the case there should be no problem with writing a file to the server host.

A thought did cross my mind concerning the operating system - XP. Are there any limitations with XP?

Have you any suggestions?

regards
Havelly

Options: ReplyQuote
Re: Possible privileges issue involving PHP and MySQL
Posted by: RiggsFolly (---.as43234.net)
Date: September 28, 2015 03:42PM

HI Havelly,

The error message indicates that you have not connected to the database with a password when one is required.

Without more of the actual code I cannot be much more help.

Why do you say you cannot access phpMyAdmin> Whats the problem there?

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: Possible privileges issue involving PHP and MySQL
Posted by: havelly (---.dyn.iinet.net.au)
Date: September 29, 2015 12:44AM

Hello Riggs

Interesting. The database has been set up without requiring a password. Many other interrogations of the database happily work - it is only this one that does not. Are you actually referring to the MySQL database password or the Windows password?

Does the database require the appropriate rights/privileges to be able to write a file to the C drive?

I'm not sure whether lack of access to phpMyAdmin is part of this issue or a separate one. When the phpMyAdmin menu option is selected a page with only phpMyAdmin logo on it is opened - there is no other content. When WampServer was installed I can not recall whether or not phpMyAdmin installation was optional or not.

regards
Havelly

Options: ReplyQuote
Re: Possible privileges issue involving PHP and MySQL
Posted by: havelly (---.dyn.iinet.net.au)
Date: September 29, 2015 01:50AM

Hello Riggs

My apologies for not including the code in the previous response. It is included below:

<?php
// connect to db host
//mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD)
$connection = mysql_connect("localhost", "mysql -u root", "" )
or die('Could not connect: ' . mysql_error($connection));

// select db
$db = mysql_select_db("test", $connection);

// create query
$query = "SELECT * INTO OUTFILE 'geolocDB.txt' FROM geoloc";

//perform query
$result = mysql_query($query);

// close mysql connection
mysql_close($connection);
?>

All the other interrogations of the database have used this connection process and as previously mentioned work. It is only this command - where writing a file to the C drive is requested - where it does not.

Options: ReplyQuote
Re: Possible privileges issue involving PHP and MySQL
Posted by: RiggsFolly (---.as43234.net)
Date: September 29, 2015 10:11AM

I think if you look closer, you have commented out the correct connection to the database!

    //mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD)

and created a new call to mysql_connect() which is invalid

$connection = mysql_connect("localhost", "mysql -u root", "" )

I assume this is also just an example, but if not you also need to add some code to test the result statuses of all these calls, specifically as the OUTFILE command will fail if `geolocDB.txt` already exists, from a previous OUTFILE attempt.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: Possible privileges issue involving PHP and MySQL
Posted by: havelly (---.dyn.iinet.net.au)
Date: September 29, 2015 01:16PM

Hello Riggs

Well, what a learning experience this has been. I have been using 'mysql -u root' for the database username in all my php scripts and they have been happily working. It was not until the "SELECT * INTO OUTFILE 'geolocDB.txt' FROM geoloc" query was used did an error occur. So using 'root' as the database username is the correct syntax - it now works.

Many thanks for your perseverance with this one.

regards
Havelly

Options: ReplyQuote


Sorry, only registered users may post in this forum.