Mysql - Search using like does not correctly return Unicode characters

Asked

Viewed 61 times

0

I have a text editor in my application that records html formatting in a longtext field. It happens that when I use the like to return the data it cannot find because of the generated Unicode characters.

I have this value in the bank (Pasta)

<p>Macarr&atilde;o</p>

Mysql

select * from oficio where integra like '%Macarrão%' LIMIT 1

and it does not return records. How do I make it to Decode this value?

  • The best thing would be to already save right in the database. Normally you would convert to HTML in the view only. Anything you do on top of this is suffered, you will have to keep converting in every operation (query, editing, etc). It’s not because your editor returns the data so you will write it so right. You can convert the HTML Entities to the desired encoding and save them to the database. When you display them on the screen, it generates the entities again, and the rest starts working. Just convert the entities to the same native encoding of your table.

  • thanks @Bacco, I searched my editor’s documentation and solved the problem

1 answer

0

In my case I am using the tinymce editor, I have discovered that in its configuration you can enable the option not to record

$scope.tinyMceOptions = {
      init_instance_callback: function(editor) {
        $scope.iframeElement = editor.iframeElement;
      },
      entity_encoding : "raw" //esta opção grava normalmente no banco
};
  • Only one correction: Unicode is one thing, Entity is another. Mysql works smoothly with Unicode, but your question example uses HTML entities (which is what you turned off with the mentioned configuration).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.