dqk42179 2017-04-09 11:51
浏览 29

插入与Laravel表中的句号(斑点)

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

  • 写回答

2条回答 默认 最新

  • matlabmann 2017-04-09 12:40
    关注

    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:

    Updating a MySQL column that contains dot (.) in its name

    评论

报告相同问题?