Log In · Register

 
Trouble With PHP/MySQL, Permissions???
Uronacid
post May 13 2009, 12:28 PM
Post #1


Senior Member
******

Group: Official Member
Posts: 1,574
Joined: Aug 2007
Member No: 555,438



The connection to the database is fine, however I keep getting the following error when I attempt to run a query:
Access denied for user 'administrator'@'localhost' (using password: NO)

Here is my PHP:
CODE
<?php
        //this script connects to the mysql server database
        
        $username = 'administrator';//stores the username
        $password = "********";//stores the password
        
        if ($dbc = mysql_connect('127.0.0.1', $username, $password)) {
            
            print '<p>Successfully connected to the MySQL!</p>'; //print a message if it was a success
            mysql_close(); // close the database
            
            if (@mysql_query('CREATE DATABASE myblog')) {//Try to create the database
                
                print '<p>The database has been created!</p>';//Creating the database was successful
                
            } else {
            
                print '<p style="color: red;">Could not create the database because:<br />;' . mysql_error() . '</p>';
            
            }
            
            if (@mysql_select_db('myblog')) {
                
                print '<p>Database has been selected!</p>';
            
            } else {
            
                print '<p style="color:red;">Could not select the database because:<br />' . mysql_error() . '</p>';
            
            }
        
        } else { //connection failed
            
            print '<p style="color:red;">Could nor connect to MySQL:<br />' . mysql_error() . "</p>";
        
        }
        
    ?>


Successfully connected to the MySQL!

Could not create the database because:
;Access denied for user 'administrator'@'localhost' (using password: NO)

Could not select the database because:
Access denied for user 'administrator'@'localhost' (using password: NO)
 
 
Start new topic
Replies (1 - 11)
mipadi
post May 13 2009, 12:57 PM
Post #2


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



Were you able to create the database?
 
Uronacid
post May 13 2009, 01:08 PM
Post #3


Senior Member
******

Group: Official Member
Posts: 1,574
Joined: Aug 2007
Member No: 555,438



QUOTE(mipadi @ May 13 2009, 01:57 PM) *
Were you able to create the database?


I applogize, here is the full read out from my PHP:

QUOTE
Successfully connected to the MySQL!

Could not create the database because:
;Access denied for user 'administrator'@'localhost' (using password: NO)

Could not select the database because:
Access denied for user 'administrator'@'localhost' (using password: NO)


I'm able to create the database from the backend using the admin username/password and the following commands:


1. mysql -u root -p
2. <my password>
3. CREATE DATABASE myblog;


I'm unable to do it via PHP.
 
mipadi
post May 13 2009, 01:12 PM
Post #4


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



What versions of MySQL and PHP are you using?
 
Uronacid
post May 13 2009, 01:14 PM
Post #5


Senior Member
******

Group: Official Member
Posts: 1,574
Joined: Aug 2007
Member No: 555,438



QUOTE(mipadi @ May 13 2009, 02:12 PM) *
What versions of MySQL and PHP are you using?


Hmmm, how would I check that on Ubuntu?
 
mipadi
post May 13 2009, 01:16 PM
Post #6


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



`php --version` and `mysql --version`
 
Uronacid
post May 13 2009, 01:17 PM
Post #7


Senior Member
******

Group: Official Member
Posts: 1,574
Joined: Aug 2007
Member No: 555,438



QUOTE(mipadi @ May 13 2009, 02:16 PM) *
`php --version` and `mysql --version`

PHP 5.2.6-2ubuntu4.2 with Suhosin-Patch 0.9.6.2 (cli)
mysql Ver 14.12 Distrib 5.0.67, for debian-linux-gnu (i486) using readline 5.2
 
mipadi
post May 13 2009, 01:25 PM
Post #8


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



Hm...that error can happen if you're using MySQL > 4.1 and PHP < 4, but it looks like you're okay. Hrm...
 
Uronacid
post May 13 2009, 01:31 PM
Post #9


Senior Member
******

Group: Official Member
Posts: 1,574
Joined: Aug 2007
Member No: 555,438



QUOTE(mipadi @ May 13 2009, 02:25 PM) *
Hm...that error can happen if you're using MySQL > 4.1 and PHP < 4, but it looks like you're okay. Hrm...


Yeah, I know, I've been browsing the internet like a wild animal looking for a reason but I just can't seem to find one. I checked the php.ini file and everything seems OK, and I don't think this has any thing to do with nginx. I would venture to guess that PHP just talks directly with the MySQL service and relays the informations back to the webserver to display on the webpage. :/
 
mipadi
post May 13 2009, 01:34 PM
Post #10


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



Oh, wait!

CODE
mysql_close(); // close the database


Probably shouldn't close the DB connection if you want to create a database or run SELECT statements.
 
Uronacid
post May 13 2009, 01:37 PM
Post #11


Senior Member
******

Group: Official Member
Posts: 1,574
Joined: Aug 2007
Member No: 555,438



QUOTE(mipadi @ May 13 2009, 02:34 PM) *
Oh, wait!

CODE
mysql_close(); // close the database


Probably shouldn't close the DB connection if you want to create a database or run SELECT statements.


OMG thank you!!!! *hug* I should have noticed that. Man, it sure helps to have a second set of eyes some time.

QUOTE
Successfully connected to the MySQL!

Could not create the database because:
;Can't create database 'myblog'; database exists

Database has been selected!
 
Mickey
post May 13 2009, 03:51 PM
Post #12


Treasure Pleasure
********

Group: Head Staff
Posts: 11,193
Joined: Oct 2005
Member No: 281,127



Topic closed & moved.
 

Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: