I have set utf8 in mysql database
now it shows
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
I have the below in the php code
mysqli_query("SET NAMES 'utf8'");
and
$con = mysqli_connect('host','user','pass','database');
mysqli_query($con,"SET NAMES 'utf8'");
Since I set utf8 in database, I am planning to remove
mysqli_query("SET NAMES 'utf8'");
and
mysqli_query($database,"SET NAMES 'utf8'");
from PHP code
I was told that I can remove the above code but I need to add
mysqli_set_charset($con,"utf8");
in the PHP code.
Instead of adding mysqli_set_charset($con,"utf8")
in the code, can I set
default_charset = "UTF-8"
in php.ini
?
my.cnf is
[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8
default-collation=utf8_general_ci
character-set-server=utf8
collation-server=utf8_unicode_ci
init-connect='SET NAMES utf8'