Good morning everybody.
I have a problem that I could not solve
I'm trying to save a record in the database with Laravel, the problem is that one of the fields has a point in its name.
This is the structure: struct table
I tried to do this:
$emqu_accountavg = DB::table('emqu_accountavg_resptime')->insert([
'company_id' => $company_id,
'#Month' => $item['#Month'],
'System' => $item['System'],
'APPLID' => $item['APPLID'],
'GUI/NoGUI' => $item['GUI/NoGUI'],
'Resptime avg. (ms)' => $item['Resptime avg. (ms)'],
]);
But this is the error I get:
QueryException in Connection.php line 647:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Resptime avg. (ms)' in 'field list' (SQL: insert into `emqu_accountavg_resptime` (`company_id`, `#Month`, `System`, `APPLID`, `GUI/NoGUI`, `Resptime avg`.` (ms)`) values (1, 12017, BWP, APPL358552, GUI, 1581,4))
I also tried to do it this way:
emqu_accountavg_resptime::create([
'company_id' => $company_id,
'#Month' => $item['#Month'],
'System' => $item['System'],
'APPLID' => $item['APPLID'],
'GUI/NoGUI' => $item['GUI/NoGUI'],
'Resptime avg. (ms)' => $item['Resptime avg. (ms)'],
]);
No error occurs and the records are saved, but the one that has point keeps it null. I check this value:
$item['Resptime avg. (ms)']
And okay, the problem is the name of that field with speckeld (point) in the database
You can see on your first error that the column laravel tries to insert to is `Resptime avg`.` (ms)` It should be `Resptime avg. (ms)`.
You can find how to properly escape the value here:
I got the answer, without specifying the names of the fields of the table, but respecting the order of the same as it is stored, thus:
DB::insert('insert into emqu_accountavg_resptime values (?, ?, ?, ?, ?, ?)', [$company_id, $item['#Month'],$item['System'],$item['APPLID'],$item['GUI/NoGUI'],$item['Resptime avg. (ms)']]);
Thanks everyone for your help.