Welcome Guest, Not a member yet? Register   Sign In
insert without data
#5

Yes i know and it really makes things easier many times, by defining $table variable and other stuff inside my Model. I like that a lot!

I would really appreciate this change. Fighted with this many times.

The exception "no data for insert" is great. Saves some time, when I forget to pass variable to insert() function. But not in case when I know what I'm doing. If I set empty array i should get query exception, directly from database like "the column XYZ has no default value set" or smthing similiar.

Imagine this scenario:

PHP Code:
$data = [];

if (
$this->request->getPost('use_reply_to')) {
    $data['reply_to_email'] = $this->request->getPost('reply_to_email');
    $data['reply_to_name'] = $this->request->getPost('reply_to_name');
}

$emailTemplate = $this->model->insert($data); 

Data array, is again empty and I want system behave according to database structure and default column values.

Currently I have to do it like this, but things could be much more easier Smile Thank you

PHP Code:
$data = [];

if (
$this->request->getPost('use_reply_to')) {
    $data['reply_to_email'] = $this->request->getPost('reply_to_email');
    $data['reply_to_name'] = $this->request->getPost('reply_to_name');
}

if (empty(
$data)) {
   db_connect()->query('INSERT INTO gallery VALUES();');

   $emailTemplateId db_connect()->insertID()
} else {
   $emailTemplateId $this->model->insert($data);

Reply


Messages In This Thread
insert without data - by webdeveloper - 06-05-2022, 04:26 AM
RE: insert without data - by kilishan - 06-05-2022, 08:56 PM
RE: insert without data - by webdeveloper - 06-07-2022, 03:12 AM
RE: insert without data - by kilishan - 06-07-2022, 06:42 AM
RE: insert without data - by webdeveloper - 06-08-2022, 05:44 AM
RE: insert without data - by kenjis - 06-10-2022, 04:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB