database creation using codeigniter database dbforge class gives "Access denied for user 'username'@'localhost' to database 'database_name' "
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:


Go to c-panel -> databases -> and create the database john123_blog
Go to databases -> users and create a user to access it john123_blogu
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.