0

Using codeigniter database dbforge class I have created a database and loaded that database as the current database and created tables in localhost WAMP server. But when I uploaded it to the server I am not able to create the database using dbforge class.

$this->dbforge->create_database($database_name)

This command line gave me the following error:

Error No 1044: Access denied for user 'username'@'localhost' to database 'database_name'    

I am using the 'cpanel' hosting provider .

EDIT1: How we can give permission for a mysql user to create database in cPanel hosting provider...?

EDIT2: The Privileges list of user does not show 'CREATE DATABASE' Privilege in Cpanel. The user is created through cPanel and it have been given all the available privileges, but the CREATE DATABASE privilege is not available in that list in cpanel.

7
  • 3
    It clearly states that specified user don't have permission to create database on the server.
    – Deepak
    Commented Sep 4, 2012 at 10:59
  • how we can give permission to create database to a user..?
    – user1645846
    Commented Sep 4, 2012 at 11:43
  • @user1645846 - are you able to create additional databases via the cPanel?
    – stealthyninja
    Commented Sep 4, 2012 at 13:54
  • @stealthyninja- yes i am able to create database through cpanel. And i have to add a user to that newly created database through Cpanal to access that database. But while creating database using dbforge class it gives access denied error.
    – user1645846
    Commented Sep 5, 2012 at 4:35
  • Is your DB user name is really "username"? Seems like you haven't changed default DB connection config.
    – webbandit
    Commented Sep 5, 2012 at 5:40

1 Answer 1

2

Using C-Panel / WHM, you create databases on a per application basis. Let's say that your c-panel username is john123 and you were installing a blog. You'd do the following:

  1. Go to c-panel -> databases -> and create the database john123_blog
  2. Go to databases -> users and create a user to access it john123_blogu
  3. Add the user to the database, and give them the appropriate permissions

At that point, you can use the dbforge class to create tables within the database. In a shared hosting setup, users are often limited to how many databases they can have, so database creation itself has to go through the automation software (in this case, c-panel).

There's nothing wrong with your code, it's just assuming a non-shared environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.