CodeIgniter Database Connection Issue

2019-09-21 16:30发布

问题:

I'm using CodeIgniter, and I'm not able to use my database with it. I'm following this tutorial exactly, but when I open in localhost I receive a 404 page.

回答1:

You need to set up your application/config/database.

Here you need to add your information for your database.

$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "yourdbusername";
$db['default']['password'] = "password_for_db";
$db['default']['database'] = "name_of_db";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

Have you done it?



回答2:

If you're getting a 404, it may not be your database connection. Check your routing, and be sure that you are accessing a page that does indeed exist. If you're accessing a controller that loads a view, stop loading the view for now and test the connection directly from the controller - output "YES" if it is, and "NO" if anything else.

If your problem persists, double-check your database-connection configuration. Lastly, I would suggest you follow the documentation rather than another website when you are getting familiar with a framework. You can view the documentation for the Database class at http://codeigniter.com/user_guide/database/index.html



回答3:

Do you try http://localhost/CodeIgniter/index.php/employee/GetAll ? Are you using CodeIgniter 2 ?



标签: codeigniter