سؤال

I created a forum on my site using my my website provider, it created the database for me and uploaded the forum, etc. Previously I uploaded the forum and created the db myself but for some reason the releases of phpbb3 are riddled with stuff like missing ?> tags

I'm trying to connect to the db using my own script, I have a few other databases which I created, and they work fine, except this one which was made by my provider

$con = mysql_connect('ip','user','pass');
if (!$con) {
    die('Not connected : ' . mysql_error());
}

$db_selected = mysql_select_db('forum',$con);
if (!$db_selected) {
    die ('Can\'t use db : ' . mysql_error());
}

I get Can't use db : Access denied for user 'user'@'%' to database 'forum'

EDIT: (fixed) was missing variable named $db_selected

هل كانت مفيدة؟

المحلول

Assuming that the user you want to use to access the database is called "user", check the following

1) Switch current db to mysql, and check if the user exists (there is a row having Host = % in the results of the following query)

USE mysql;
SELECT * FROM user WHERE user = 'user'

2) Check if this user has permissions for the database (there is a row having Db = database and host = %)

SELECT * FROM db WHERE user = 'user'

3) If this looks fine, try to flush privileges by the following:

FLUSH PRIVILEGES;

Then try to log in .. it may help.

The full step by step how to create a user and grant privileges is here:

http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top