Welcome Guest, Not a member yet? Register   Sign In
Database Error Handling
#2

couple of things to mention if in your index.php inside public you have
$_SERVER['CI_ENVIRONMENT'] = 'development';

you will get loads of info on error.

if you change that to:
$_SERVER['CI_ENVIRONMENT'] = 'production ';

its a different kettle of fish.


There are different ways to handle possible errors ;but really wrong field or wrong table shouldn't be one of them since you are pretty much forced to get it right when you create a model.

eg


protected $table = 'portfolio';
protected $primaryKey = 'Id';
protected $allowedFields = ['image','imageTitle','slug'];

there are things that have crossed my mind though such as when there are no records in database

i've got around this in controller with tests such as :
$handle= new PortfolioModel();
$mycount= $handle->count();

if($mycount == 0)

{
//do something
}

but if i deliberately spelt a field wrong eg for table in my model, then in a controller basic block try catch works
try
{

$handle= new PortfolioModel();
$mycount= $handle->count();

}


catch ( \Exception $e)

var_dump($mycount);
echo $e->getMessage();

{

//here i got null
}
the level of output depends on whether you have development or production in index.php


for above when index.php has in production mode output is just one line :

NULL SQLite3::query(): Unable to prepare statement: 1, no such table: portfoliol
Reply


Messages In This Thread
Database Error Handling - by next2heaven - 04-17-2020, 09:46 AM
RE: Database Error Handling - by captain-sensible - 04-17-2020, 11:22 AM
RE: Database Error Handling - by next2heaven - 04-17-2020, 02:01 PM
RE: Database Error Handling - by MGatner - 04-22-2020, 04:37 AM
RE: Database Error Handling - by next2heaven - 04-22-2020, 08:31 AM
RE: Database Error Handling - by jreklund - 04-22-2020, 11:11 AM
RE: Database Error Handling - by next2heaven - 04-22-2020, 11:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB