Skip to content

Bug: MySQL Errors are not reported #3204

Description

@din-psnl

Describe the bug
When I insert the data to database using a model, If any MySQL errors exits, Its not being reported.

$userModel = new \App\Models\UserModel();

$newUser = [
	'name'	 	=> $this->request->getVar('name'),
	'username'	=> $this->request->getVar('username'),
	'email'		=> $this->request->getVar('email'),
	'password'	=> $this->request->getVar('password'),
];
 
$user_id = $userModel->insert($newUser);

// here the name column does not exists in the database 
$user_id returns '0'

//But when I try 

$userModel->errors();  //Returns nothing 

The only way I can see there is an error is var_dump($userModel) // and go through the whole array to see the error

and here is my model

namespace App\Models;

use CodeIgniter\Model;

class UserModel extends Model
{
    protected $table      = 'users';
    protected $primaryKey = 'id';

    protected $returnType     = 'array';
    protected $useSoftDeletes = true;

    protected $allowedFields = ['name', 'email', 'username','password'];

    protected $useTimestamps = true;
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';
    protected $deletedField  = 'deleted_at';

    protected $validationRules    = [];
    protected $validationMessages = [];
    protected $skipValidation     = false;
 
} 

CodeIgniter 4 version
CodeIgniter 4.0.3

Affected module(s)
Models

Context

  • OS: macOS Mojave
  • Web server Apache
  • PHP version : 7.4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions