CodeIgniter Forums
FIX: "Fatal error" reporting errors in DB_driver.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: FIX: "Fatal error" reporting errors in DB_driver.php (/showthread.php?tid=46791)



FIX: "Fatal error" reporting errors in DB_driver.php - El Forum - 11-15-2011

[eluser]Unknown[/eluser]
Trying to connect to a SQLite3 database on a new 2.0.3 install. Looks like 2.1.0 still has the same code, so I'm going to post my fix here for the sake of all...

Initial output:
Quote:Fatal error: [] operator not supported for strings in /var/www/system/database/DB_driver.php on line 1183

It seems that an error message is being built as an array before it is passed on, but it actually gets initialized as a string.

The fix is as follows (just a bit above line 1183):
Quote: if ($native == TRUE)
{
- $message = $error;
+ $message[] = $error;
}
else
{
- $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;

+ $message[] = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;

}

And after that, I get a much more useful error that I can use to troubleshoot my environmental problems:
Quote:A Database Error Occurred

file is encrypted or is not a database

Filename: core/Loader.php

Line Number: 268



FIX: "Fatal error" reporting errors in DB_driver.php - El Forum - 06-22-2012

[eluser]Unknown[/eluser]
Your fix doesn't take into account the fact that $message could be an array or a string. You're also ensuring that $message is a multidimensional array if $native is set to FALSE. The following will fix this across the board and not introduce errors when this function is used with different parameters.

[code]

if ($native == TRUE)
{
- $message = $error;
+ $message = ( ! is_array($error)) ? array($error) : $error;
}
else
{
[code]