+ Reply to Thread
Results 1 to 3 of 3

Thread: Access denied to mysql database

  1. #1
    tomfordx is offline x10Hosting Member tomfordx is an unknown quantity at this point
    Join Date
    Jan 2012
    Posts
    4

    Access denied to mysql database

    Basically I am trying to run some code to insert some data into my database. I have a seperate file to connect to the data base:

    Code:
    <?php
    $link = mysql_connect('localhost', '*****', '*****');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    $db_selected = mysql_select_db('******', $link);
    if (!$db_selected) {
        die ('Can\'t use database : ' . mysql_error());
    ?>
    Then in a file called register.php I include the config.php and that page then loads perfectly fine. you hit register and tries to insert the data into the database I get this error message:

    Access denied for user '*****'@'localhost' (using password: NO)

    Now I have double checked my user and password information for the database and it is correct so HELP!

  2. #2
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: Access denied to mysql database

    Have you remembered to prefix your database name and MySQL user name with your cPanel user name? (The format is cpanelusername_databasename and cpanelusername_databaseusername.)
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Access denied to mysql database

    Quote Originally Posted by tomfordx View Post
    Access denied for user '*****'@'localhost' (using password: NO)
    The script is trying to connect without a password somewhere. Perhaps another mysql function is being called before mysql_connect, which will attempt to connect with default parameters. This is one reason the connection should always be specified when calling the mysql functions.

    The mysql extension is outdated and on its way to deprecation. Instead, use PDO, which has many useful improvements, such as prepared statements and support for the Traversable interface, so you can loop over results with foreach. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO".

    Be sure to read the MySQL articles on the X10 Wiki.
    Last edited by misson; 01-07-2012 at 03:18 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 06-04-2010, 05:43 AM
  2. Database Access Denied issue
    By eric.toronto in forum Free Hosting
    Replies: 4
    Last Post: 04-14-2010, 02:15 PM
  3. Site is down, database access denied
    By vekou in forum Free Hosting
    Replies: 3
    Last Post: 02-14-2010, 04:07 AM
  4. Access denied to database
    By drunkie in forum Free Hosting
    Replies: 6
    Last Post: 10-10-2009, 06:07 PM
  5. Replies: 3
    Last Post: 02-14-2008, 01:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers