HTTP 500 error displayed when trying to connect to mysql database to retrive the query results |
[eluser]malcom1234[/eluser]
Hello, I'm a CI newbie and I need your help in fixing the issue related to the load->database() function in the model class. My situation is below... I created a model class called Users and I am connecting to the database from a function called get_all_entries() which will be called from the controller class. The controller calls the model->function and the model has code like below in the function... function get_all_entries(){ $dsn = 'mysql://root:admin@localhost/search'; $this->load->database($dsn); return $query->result(); } My issue is this fun gets called but I do not see the control coming back to the controller class from the model class. I tried commenting all lines in the model and the control comes back to model this time. I checked to see if there is any database related errors and I do not see anything being logged like that. Only log I see in CI logs is below.. DEBUG - 2011-05-12 23:52:52 --> Router Class Initialized DEBUG - 2011-05-12 23:52:52 --> Output Class Initialized DEBUG - 2011-05-12 23:52:52 --> Security Class Initialized DEBUG - 2011-05-12 23:52:52 --> Input Class Initialized DEBUG - 2011-05-12 23:52:52 --> Global POST and COOKIE data sanitized DEBUG - 2011-05-12 23:52:52 --> Language Class Initialized DEBUG - 2011-05-12 23:52:52 --> Loader Class Initialized DEBUG - 2011-05-12 23:52:52 --> Controller Class Initialized DEBUG - 2011-05-12 23:52:52 --> Model Class Initialized DEBUG - 2011-05-12 23:52:52 --> Model Class Initialized DEBUG - 2011-05-12 23:52:52 --> Database Driver Class Initialized To me it appears that DB connection is fine but there are not errors and I am not sure what is going on..as there is no meaningful log inspite of loglevel set to 4... Does anyone have the same issue? Can someone help me? thanks for your help in advance Malcom
[eluser]toopay[/eluser]
[quote author="malcom1234" date="1305289037"] The controller calls the model->function and the model has code like below in the function... function get_all_entries(){ $dsn = 'mysql://root:admin@localhost/search'; $this->load->database($dsn);[/quote] Thats should be just Code: function get_all_entries()
[eluser]malcom1234[/eluser]
thanks for the reply... I initially used $this->load->database(); But I have the same issue..I get a blank page and I do not get anything in logs when i used $this->load->database($dsn); I used database.php script and the settings are below.. $active_group = 'default'; $active_record = TRUE; $db['default']['hostname'] = 'localhost'; $db['default']['username'] = 'root'; $db['default']['password'] = 'admin'; $db['default']['database'] = 'search'; $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; $db['default']['db_debut'] = TRUE; /* End of file database.php */ /* Location: ./application/config/database.php */ pls advise. Malcom
[eluser]malcom1234[/eluser]
I included mysql default port as well now in database.php and still no use... here is my code $this->load->database(); $query = $this->db->get('users'); foreach ($query->result() as $row) { echo $title; } title is a variable that i am just echoing..if above runs successfully, i route to a view page... My view page gets rendered if i have nothing in this model's function..which means the above lines are causing problem.. pls suggest.. thanks malcom |
Welcome Guest, Not a member yet? Register Sign In |