Jump to content

[SOLVED] 'Access Denied' to MySQL database - a simple problem for an expert


Recommended Posts

Hi there

 

I am a little new to php having been working in the dark world of databases for many years. I am in the process of creating my first website but whilst the php and the database stuff work great I cannot get the two to talk. The error is: DB connection failed: Access denied for user 'phpaccess'@'localhost' (using password: YES). I think this is likely just a small config or privilege tweak - can any of you experts help? The user is  'phpaccess'@'%' and only has select privilege on db_mydatabase - nothing else

 

As always thanks for your time in advance and code below, php 5.2, MySQL 5.1:

 

----Test PHP File
<HEAD><TITLE>HTML, PHP, MySQL Test Page</TITLE></HEAD>
<BODY>
<?PHP
//Run phpinfo to make sure MySQL is loaded and working
    phpinfo();
    
//Set up database connection parameters
    $myServer = "127.0.0.1";
    $myUser = "phpaccess";
    $myPass = "phppassw0rd";
    $myDB = "db_mydatabase";
        
//Open mySQL connection with all errors reported
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    $connection = mysql_connect($myServer, $myUser, $myPass);
    if (!$connection)
    {
       die("DB connection failed: " . mysql_error());
    }

//Activate database and then query the table
    $activedb = mysql_select_db($myDB, $connection) or die ("Couldn't open database");
    $query = mssql_init("SELECT * FROM `tb_users`", $connection);
    $result = mssql_execute($query);
    echo "success";

    mysql_close($connection);
?>

Ok - We have a solution:

 

Thanks Mr Bolson - I did have to change the server to localhost but also had to change the users login from 'phpaccess'@'%' to 'phpaccess'@'localhost'

 

And then it all suddenly worked!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.