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)