Database access issues

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Tay
Forum Newbie
Posts: 6
Joined: Wed Aug 09, 2006 10:39 pm

Database access issues

Post by Tay »

I have a php/mysql site which works fine locally, but no longer works completely on my remotely hosted server.

On four pages, a query runs to extract db information. This displays correctly. On this page, one should be able to click on a name or photo and then another query is run and a new page is opened displaying the results from another query. However, I get the following message when I make the appropriate click:

Code: Select all

Access denied for user 'user'@'localhost' to database 'databasename'
If access was denied to this user, the other four pages would not work, but they do; they all use the same database. I have created new users, altered access rights and I still get the same error message. I am stumped completely; I do not understand how access is allowed for some pages, but not for another.

The php access include file is:

Code: Select all

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_dbConnect = "localhost";
$database_dbConnect = "databasename";
$username_dbConnect = "user";
$password_dbConnect = "password";
$dbConnect = mysql_connect ($hostname_dbConnect, $username_dbConnect, $password_dbConnect) or trigger_error(mysql_error(),E_USER_ERROR); 

?>
The chunk of code on each of the relevant pages to access the php include is:

Code: Select all

<?php require_once('dbconnect.php');
mysql_select_db($database_dbConnect, $dbConnect);
*Names changed.

As I said, the site had worked fine. I then uploaded some files which worked ok locally (but needed tweaking 'live'), and on the same day the host server 'had problems' with php file security. I assume that this problem is of my making, but as I know that other sites on this server had php pages hacked, I'm not sure that the files that I uploaded are the cause. I have now changed hosting company.

I'd be grateful if somebody could point me in the right direction as I've spent many hours seaching forums and manuals but can't get to the bottom of it, and would like to know how access rights can be fine for one page but not another.
Last edited by Tay on Thu Aug 10, 2006 2:07 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$dbConnect isn't one of your variables. Typo?
Tay
Forum Newbie
Posts: 6
Joined: Wed Aug 09, 2006 10:39 pm

Post by Tay »

Hi

Thanks feyd. I have edited my post above; I made a typo when cleaning up the code to put on here.

I have checked and checked again, but there are no typos locally, so the problem still stands.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Tay wrote:I made a typo when cleaning up the code to put on here.
Please, no special (untested) "forum edition" of your script. Isn't the original supposed to be at least as clean as the snippet you post here? It doesn't speed up things if we have to guess wether it's a typo or the "real" error.
Tay wrote:The chunk of code on each of the relevant pages to access the php include is:
How much irrelevant code is there between those two lines of relevant code?
What does

Code: Select all

echo '<div>'; var_dump($dbConnect); echo '</div>';
mysql_select_db($database_dbConnect, $dbConnect);
print?
Tay
Forum Newbie
Posts: 6
Joined: Wed Aug 09, 2006 10:39 pm

Post by Tay »

Thank you for replying.

The var dump results were:
resource(3) of type (mysql link)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Ok, that's a dead end.

Just another question. $database_dbConnect is set in dbconnect.php, why isn't mysql_select_db called there?
Tay
Forum Newbie
Posts: 6
Joined: Wed Aug 09, 2006 10:39 pm

Post by Tay »

Thanks.
$database_dbConnect is set in dbconnect.php, why isn't mysql_select_db called there?
I don't know why it wasn't called there. I have just tried the dbconnect.php with the mysql_select_db added, but I still get the same results.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Sorry, really escapes me then.
Tay
Forum Newbie
Posts: 6
Joined: Wed Aug 09, 2006 10:39 pm

Post by Tay »

Thank you for your help and suggestions. Thought I was going mad, but perhaps not?

If I find the answer, I'll post back.

Thanks again.
Tay
Forum Newbie
Posts: 6
Joined: Wed Aug 09, 2006 10:39 pm

Post by Tay »

Hello again

Just to clear this thread up; I have resolved the issue.

Within a query, I hadn't explicitly referenced a table, and this caused the 'access denied' error. What was

FROM

databasename.tablename AS testvar

needed to be

FROM

identifier_databasename.tablename AS testvar

I don't know if identifier is the correct term here.... Anyhow, all is working, although this seems a rather long-winded way to do things; especially as I don't have to add the identifier as a prefix to any other table. Still haven't figured that out.

Thanks for your help. :)
Post Reply