Jump to content

Mysql Remote Error Shows Wrong Userid


Recommended Posts

I'm trying to write a Wordpress 2.8 widget. The widget will need to access a MySql database. I have a connection script that does this:


>// Set database info
define('DB_HOST', 'my-domain-name.com');
define('DB_USER', 'myhome_username');
define('DB_PASSWORD', '********');
define('DB_DATABASE', 'myhome_databasename');

// connect to the database
$mysql = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE)
or die('Could not connect: ' . mysql_error());
$db_selected = mysql_select_db('myhome_databasename', $mysql);
if (!$db_selected) {
  die ('Can\'t use myhome_databasename : ' . mysql_error());



When the script runs and tries to connect I receive this error:


>Can't use myhome_databasename : Access denied for user 'myloginid'@'%' to database 'myhome_databasename'


I just cannot figure out where the Mysql server is getting the "myloginid" -- I would have expected an error with "myhome_username". Anybody have any idea what could cause this? I've been looking at it so long my eyeballs are falling out. I have set up the remote access to allow "%" and have added user "myhome_username" to "myhome_databasename"


If I fall back to using a local mysql database on my XAMPP installation everything works just fine of course. Any help is appreciated.

Link to comment
Share on other sites

Why are you passing in DB_DATABASE to the mysql_connect() function? It is not needed at that point.


I doubt that would cause this issue as it seems to get passed the mysql_connect() without returning the error. Worth cleaning up anyway.


Is the "myloginid" it is returning your cpanel login? im just a bit confused by the phrasing of it.

Link to comment
Share on other sites

Apologies - I inserted some generic text into the specific fields so as not to put my login info into the public domain. I appreciate your reply and your advice about cleaning up the connect string. I'm going to pursue the login problem from another angle.


Thank you,

Link to comment
Share on other sites

In connection scripts on a shared server is it necessary to prefix both the user and the database with your TCH userID?


It appears that way in cPanel > MySQL Databases. Everything gets prefixed (because one instance of MySQL handles all databases of all websites on the server, and the prefix ensures unique names). What I'm not sure of is whether you must use the prefix in your connection scripts.


So a database db1 would be referred to as YourTCHuserID_db1.

Your MySQL database user would be referred to as YourTCHuserID_DBUserName.


That would probably be a difference between your TCH server and your local XAMPP.


Edit: yes, I think the prefix is necessary. I found the connection settings for SMF Forum, and it uses the prefixes.

Edited by SteveW
Link to comment
Share on other sites

When you create the database user in cPanel > MySQL Databases, you don't enter the userID prefix for the username or the database name. cPanel prepends the prefix for you. You'll see that it did when you go back to the database summary screen from the add user confirmation screen.

Link to comment
Share on other sites



Thanks for taking the time to reply. Yes, my userids are correctly constructed and have the proper prefix etc. I've got enough work to do right now that I'm simply going to leave this alone for a while and I'll be that when the time comes I need to try this again I'll probably have no trouble. Thanks very much for taking the time to respond.

Link to comment
Share on other sites

Join the conversation

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

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...