Query in mysql with php does not return result in queries with accents

Asked

Viewed 2,109 times

2

Hello I have a system in php/mysql using zend 1.12, but when consulting the mysql database with a word that has no accent and in the table has accent, does not return any result for example:

when searching: {Joao} and in the database this {john}, does not return results.

the database is configured with: Innodb latin1_general_ci.

I want to know if there is a way I remove the accents from the records that are already in the table for the query to occur naturally when the user does the word search without accent.

ex: usuario digita: {atencao} in the table I have the phrase: {Be very careful when returning from the trip.}

this returns 0 result.

I do not know if I could be clear, I have looked here on the forum and I did not find anything like.

if someone can indicate a link or give some hint or even clarify this.

Thank you.

  • See if this helps you: http://answall.com/a/51317/3635

1 answer

3


You can perform the query without it considering the accent as follows:

SELECT *
FROM minhaTabela
WHERE minhaColuna LIKE '%joao%' COLLATE utf8_general_ci

Considerations

Alternative

You can resolve the issue faster by editing the table in the database and changing the collation of the column where you are performing the search for UTF-8, specifically the utf8_unicode_ci, thus ensuring that accented letters will be identified in their version with or without accent.


Zend 1.12

To perform the query using the object Zend_Db_Select via interface Fluent:

$select = $db->select()
    ->from( "minhaTabela", "*" )
    ->where( "minhaColuna LIKE '%joao%' COLLATE utf8_general_ci" );
  • And how do I use Zend 1.12? without changing the collation of the bank.

  • @rafaelphp I edited the answer and added example.

  • 1

    worked right here putting the COLLATE in sql, also tested changing the collation of the table to utf8_general_ci and also worked without the need to put in sql. Thank you very much. Another question: What do you think is better? Change the collation of the tables and/or database or leave in the same sql as in the example you did? Thank you again.

  • @rafaelphp Switching in the database, your tables and their fields is always better. If you leave that question to be resolved in the consultations, not only do you have more code to keep in the future, but you are likely to lose more time by some forgetfulness that you need to specify the COLLATE.

Browser other questions tagged

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