3

I have table named users in which users first name & last name are gets inserted. User name may contains special character also like "Cé".

So, when I go for search user from user table with special character as mentioned above(e.g. Cé) it returns the value in mysql but does not display in PHP array.

Search with normal keywords work properly in mysql as well as in PHP. But the issue raised for special character search. It search from query but it does not return in PHP variable.

I have written the below query.

SELECT first_name,last_name users WHERE concat(first_name,' ',last_name) LIKE '%Cé%' status='active';

It returns the result in MYSQL but not in PHP.

2 Answers2

3

It is related to charset.

If mysqli

$mysqli = new mysqli("localhost", "root", "password", "database"); // Change this accordingly.  
$mysqli->set_charset("utf8"); // set charset

If mysql

$mysql = mysql_connect('localhost', 'user', 'password');// Change this accordingly.     
mysql_set_charset('utf8',$mysql);// set charset

Set chatset and try again.

Nikhil
  • 1,450
  • 11
  • 24
  • $this->connection=mysql_connect($this->HOST_NAME,$this->DB_USER_NAME,$this->DB_USER_PASSWORD) or $this->DieError("I cannot connect to the database because: "); $this->SelectDatabase(); I have this type of connection. Where to insert the charset?? – Imtiyaz Shah Dec 23 '15 at 06:18
  • Thank u Nikhil :) It works... – Imtiyaz Shah Dec 23 '15 at 06:26
  • Glad to know bud :-), Note: Method which you are using is suppose to deprecate. Try to update your methods. – Nikhil Dec 23 '15 at 06:34
2

The mysqli_set_charset() function specifies the default character set to be used when sending data from and to the database server.

$mysqli->set_charset("utf8")

or

// Change character set to utf8
mysqli_set_charset($con,"utf8");

Note: For this function to work on a Windows platform, you need MySQL client library 4.1.11 or above (for MySQL 5.0 you need 5.0.6 or above).

Read more

Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20