CodeIgniter Database Connection Issue - codeigniter

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.

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?

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

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

Related

how to set up two codeigniter applications running on same server

I build a codeigniter app a few months ago - it's a networking tool.
Now my client wants me to build a reporting application for them - accesses the same database the networking tool does, but it's not really related.
I've downloaded a fresh / newer copy of codeigniter into a new folder under www ... but now I'm wondering this is the right way to architect the solution .. physically.
Has anyone else tried building multiple ci applications on the same server? Should I be / Can I combine disparate apps so that they use the same copy of the ci code?
I've read somewhere about HMVC. Does that apply here? I'm going to google now as well to read up on it, but if you can just point me in the right direction, that'd be great.
Any comments would be appreciated.
You can do either.
See http://ellislab.com/codeigniter/user-guide/general/managing_apps.html for details on using the same CI install to run multiple sites.
Alternatively, you could create another CI install in another folder and point your server software or users at it.
suppose you have two application on same server using same session names and if you login it logins another application also to avoide this issue you just need to go to config.php file under application folder and provide the unique name to cookies session
For Application a
$config['sess_cookie_name'] = 'applicationa';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
For Application b
$config['sess_cookie_name'] = 'applicationb';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;

Codeigniter login issue.

I have codeigniter powered application and whenever i tried to log in on local server it doesn't let me in without any error message. But when I login in live server it works fine.
#What might be main causes of this issue.
#My config file and database settings are correct
$config['sess_match_useragent'] = FALSE;
$config['phpass_hash_portable'] = TRUE;
//database settings:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'alumniconnect';
$db['default']['dbdriver'] = 'mysql';
I am using phpass for hashing password and tank_auth for authentication.
Thanks in advance.

codeigniter sessions issue on Chrome

I have a seriuos problem with codeigniter sessions using database, on Chrome:
when i use chrome developers tool and i refresh the page , the session is destroyed.
This my session config:
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'cisessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
Have you any idea about that ?
are you sure that the session is destroyed? I think that it's just not getting updated as supposed and it creates a new one on every page request. (common Codeigniter's setting issue)
here's my suggestions:
double check your Application/Config/config.php file to ensure that the part of session domain looks like that if you host the site on the main directory:
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "yourdomain.com";
$config['cookie_path'] = "var/sessions/";
$config['cookie_secure'] = FALSE;
and like that if you host the site on a sub-directory:
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "yourdomain.com";
$config['cookie_path'] = "siteSubDirectory/var/sessions/";
$config['cookie_secure'] = FALSE;
and also make sure that the 2 directories are writable by fixing their permissions to 755 or so, and I strongly recommend that you enable database session, it's more secure and will help you find out the real problem by checking the session table. good luck :)

Codeigniter : database configuration

I am beginner for CI so don’t have good knowledge.
My problem is:
I am not using any database. All the records are fetched from JSON.
Therefore I don’t think I need to configure database…
As said by CI, it doesn’t necessarily ask for database.
So my database.php configuration is :
$active_group = ‘default’;
$active_record = FALSE;
$db[‘default’][‘hostname’] = ‘’;
$db[‘default’][‘username’] = ‘’;
$db[‘default’][‘password’] = ‘’;
$db[‘default’][‘database’] = ‘’;
$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’;
$db[‘default’][‘swap_pre’] = ‘’;
$db[‘default’][‘autoinit’] = TRUE;
$db[‘default’][‘stricton’] = FALSE;
It works in my local system but doesn’t work in live server. I am so surprised.
Then I provided hostname, username, password and dbdriver, it works.
My question is that, is that necessary to provide all the details if I am not using database?
Thank you for your suggestion.
just dont call the Database class dont put it in the autoload.php
CI dont force you to use database

CodeIgniter Modular Extensions HMVC database error

I installed CodeIgniter latest version and Modular extension HMVC Wiredesignz HMVC Bitbucket.
It is showing annoying error in my server. If I refresh the same page for 100 times 5-10% of total refresh show this error.
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: /Library/WebServer/Documents/modular/third_party/MX/Loader.php
Line Number: 96
Screenshot of the Error
Code in Autoload Configuration file ./autoload.php.
$autoload['packages'] = array(APPPATH.'third_party');
$autoload['libraries'] = array('database');
Code in database configuration file ./database.php.
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '*****';
$db['default']['password'] = '*****';
$db['default']['database'] = '*****';
$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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Hope I am clear. Thanks in advanced.
Try setting one or both these attributes to FALSE:
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
It was not HMVC issue, when I change the host it is working perfectly. There might be some database server issue or file permission issue with some hosting or your settings.
Phil, Author of HMVC explained here
Trouble with HMVC modular extensions for CodeIgniter
change password of database user
set it simple like mydb.123
and test
in my case it works

Resources