PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 17, 2022

[FIXED] Invalid datetime format: 1366 Incorrect string value

 February 17, 2022     laravel, laravel-5.5, mariadb, mysql, php     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing