Permissions problem using PHP with mySQL

Permissions problem using PHP with mySQL

Posted by: mollita
Posted on: 2006-06-15 09:58:00

I'm having a hard time tracking down what I think is a permissions problem. I'm using php5 with mySQL. I've included three things below. The error message, the php code, and mysql session showing I am a mysql user and the absence of the hit_counter database.

The php code is supposed to create the hit_counter database. It didn't.

Can anyone point me in the right direction? Thanks in advance.
-molly

The error:
___________________________
Unable to execute the query.

Error code 1044: Access denied for user 'mollitoff'@'205.196.208.0/255.255.240.0' to database 'hit_counter'
___________________________

On the following code:


____________________________
<?php

$DBConnect = mysqli_connect("mysql.zackcourtney.com", "mollitoff", "passwordsuppressedforthispost")
Or die("<p>Unable to connect to the database server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";


$DBName = "hit_counter";
if (!@mysqli_select_db($DBConnect, $DBName)) {
$SQLstring = "CREATE DATABASE $DBName";
$QueryResult = mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
echo "<p>You are the first visitor!</p>";
mysqli_select_db($DBConnect, $DBName);
}

$TableName = "count";
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = mysqli_query($DBConnect, $SQLstring);
if (!$QueryResult) {
$SQLstring = "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY)";
$QueryResult = mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to create the table.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
}


$SQLstring = "INSERT INTO $TableName VALUES(NULL)";
$QueryResult = mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";


$Hits = mysqli_insert_id($DBConnect);
echo "<h1>There have been $Hits hits to this page!</h1>";
mysqli_close($DBConnect);

?>

________________

I am able to connect using the mollitoff user on a test database I created (see below) but the php code that I thought would create and populate a database doesn't seem to work (it also didn't appear when I used the SHOW DATABASES command, also below).


______________________
euro:~> mysql -u mollitoff -p -h mysql.zackcourtney.com test_table
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 204028 to server version: 5.0.18-standard-log

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test_table |
+--------------------+
2 rows in set (0.00 sec)


Re: Permissions problem using PHP with mySQL

Posted by: guice
Posted on: 2006-06-15 10:27:00

In reply to:

The php code is supposed to create the hit_counter database. It didn't.


That is because you do not have permission to create databases directly within MySQL.

Re: Permissions problem using PHP with mySQL

Posted by: mollita
Posted on: 2006-06-15 11:29:00

Thank you so much for replying. Could you clarify:

Is this because I've failed to assign the correct permissions somewhere?

Or are you saying users at dreamhost are not allowed to do this?

And I think there may be something else going on because I went in through ssh mysql monitor and tried to use CREATE DATABASE to create it and got:

mysql> CREATE DATABASE hit_counter;
ERROR 1044 (42000): Access denied for user 'mollitoff'@'205.196.208.0/255.255.240.0' to database 'hit_counter'

It's the same error message. I am logged in as user mollitoff already. I created a different database earlier called "test_table" using the same command and it worked.

Here is my output from SHOW DATABASES;

mysql> SHOW DATABASES;
--------------------
| Database |
--------------------
| information_schema |
| test_table |
--------------------
2 rows in set (0.00 sec)

Edited by mollita on 06/15/06 11:46 AM (server time).

Re: Permissions problem using PHP with mySQL

Posted by: guice
Posted on: 2006-06-15 12:36:00

In reply to:

Or are you saying users at dreamhost are not allowed to do this?


That is the reason.

If you need to create a MySQL database, you have to use the interface provided in the web panel. You cannot create a database directly. ie: Shared users do not have the access to run "CREATE DATABASE" command within MySQL or run "mysqladmin create" on the command line.

Tags: php codemysqlhit counterright directionaccess deniederror messagephp5absence