Mysql: SET NAMES utf8 for each connection?

I use the following statement on every page of PHP to establish a connection to Unicode:

mysql_query ('SET NAMES utf8');

Is there any way to skip this? By installing something on the server? I have a VPS, so I have to have access to everything.

I suppose the real question is: do I need? Will it speed up, will I skip this statement for every HTML page that comes with?

+5
source share
3 answers

you can change mysql config (my.cnf)

[client]
default-character-set=utf8

[mysqld]
default-character-set=utf8
+8
source

When starting a new connection, there is no harm and an effective impact on performance.

, . .

+2

Why don't you just include a configuration file on every page that contains everything related to creating a db connection?

This line is integral because you can really mess up data encoding in db (was there, done so :))

+1
source

All Articles