CodeIgniter is an open source PHP framework, for use in building dynamic websites with PHP. it is lighter and faster like a framework. It is a very small footprint. It is a simple and elegant toolkit for creating full-featured web applications. It is supported popular model–view–controller (MVC) development pattern.
Under development, controller classes are a necessary part of CodeIgniter development and models or views is optional. It allows developers to maintain a modular grouping of Controller, Models, and Views (HMVC Pattern).
Rasmus Lerdorf is a father of CodeIgniter. It released by EllisLab on February 28, 2006.
Now we are going to see those errors when we connect MySQL database to CodeIgniter. Under development phase, We got an error with connecting CodeIgniter models to the MySQL database. Here we are going to explain, How to solve an error when it occurs on the CodeIgniter website.
Error: Error Number: 2006 MySQL server has gone away
SELECT `data` FROM `ci_sessions` WHERE `id` = '79548594afa414c24f1f05f4e37e9466b6c8ff20' Filename: libraries/Session/drivers/Session_database_driver.php Line Number: 169
Solution: max_allowed_packet SHOW VARIABLES LIKE 'wait_timeout' SET session wait_timeout=300; Since this is a shared server the wait time out remains same on the server.(Hostgator) |
Error:
Error Number: 2013 Lost connection to MySQL server during query
INSERT INTO `ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('640de31412f4118c988493eb0bd99c36f48b9787', '103.217.133.215', 1547615169, '__ci_last_regenerate|i:1547615142;id|s:40:\"640de31412f4118c988493eb0bd99c36f48b9787\"; is_admin_login|a:4:{s:2:\"id\";s:1:\"1\";s:10:\"login_name\";s:5:\"admin\";s:9:\"user_name\"; s:13:\"administrator\"; s:10:\"department\"; s:2:\"SA\";}')
Filename: libraries/Session/drivers/Session_database_driver.php
Line Number: 236
Solution: Change Primary key and Unique key in ci_sessions DB. sessUniId |
Error:
A PHP Error was encountered Severity: Warning
Error Message: Cannot modify header information - headers already sent by (output started at /home/servername/public_html/system/core/Output.php:528)
Filename: core/Common.php
Line Number: 573
Backtrace:
Solution: Extra spaces or lines before php tag error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED); |
Error:
A PHP Error was encountered Severity: Warning
Message: mysqli::query(): Couldn't fetch mysqli
Filename: views/mobile-productdetail.php
Line Number: 694
Backtrace:
File: /home/servername/public_html/application/views/mobile-productdetail.php Line: 694 Function: query
File: /home/servername/public_html/application/controllers/Productdetails.php Line: 186 Function: view
File: /home/servername/public_html/index.php Line: 321 Function: require_once
Solution: You are closing connection too early with DBconnection->close(); ! Do it after your queries !
Issue Explanation: Please don't insert xxx->close(); into __destruct(), because connection becomes closed immediately whenever CLASS finishes loading. |
Error:
A PHP Error was encountered Severity: Notice
Message: Trying to get property of non-object
Filename: views/mobile-productdetail.php
Line Number: 696
Backtrace:
File: /home/servername/public_html/application/views/mobile-productdetail.php Line: 696 Function: _error_handler
File: /home/servername/public_html/application/controllers/Productdetails.php Line: 186 Function: view
File: /home/servername/public_html/index.php Line: 321 Function: require_once
Solution: This happens when you assign a variable:
$foo = myfunction();
And also you are trying to access the object oriented property of a variable:
echo "$foo->total";
But the value assigned was not an object. What if myfunction() returned null or false or an integer even an array? Those don't have OO properties.
As you know that, PHP is a loosely typed language, that means a variable doesn't need a declaration of type, and you can store anything in that variable. Also, a function can return values of different types. It's up to you to figure out what type a variable holds.
$foo = myfunction(); if ($foo instanceof MyObject) { echo "$foo->total"; } |