[SOLVED] Invalid datetime format: 1366 Incorrect string value

Issue

I’m getting this error:

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: ‘\xBD Inch…’ for column ‘column-name’ at row 1

My database, table, and column have the format utf8mb4_unicode_ci also column-name is type text and NULL.

This is the value of the column-name

[column-name] => Some text before 11 ▒ and other text after, and after.

However I wait that laravel adds quotes to column’s values, because the values are separated by commas (,). It should be as follow:

[column-name] => ‘Some text before 11 ▒ and other text after, and after.’

See below the Schema

    Schema::create('mws_orders', function (Blueprint $table) {
        $table->string('custom-id');
        $table->string('name');
        $table->string('description')->nullable();
        $table->string('comment')->nullable();
        $table->integer('count')->nullable();
        $table->text('column-name')->nullable();
        $table->timestamps();

        $table->primary('custom-id');
    });

I have been looking for on google but not any solution, yet.

Anyone has an idea how to solve this issue?

I’m using Laravel 5.5 and MariaDB 10.2.11.

Solution

I solved it, encoding to uft-8 all string columns that generated this error before insert. For example, the column that generated the error was column-name, I encoded as show bellow. Also I found other column with the same error, I used this solution, too.

$data [
//key=>values 
];

$myModel = new MyModel(); 

$data['column-name'] = DB::connection()->getPdo()->quote(utf8_encode($data['column-name']));

$myModel->insert($data); 

Answered By – gvd

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published.