Does mysql_set_character change the characterset of ALL dbs?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
g_p
Forum Newbie
Posts: 13
Joined: Sun Jan 25, 2009 9:49 am

Does mysql_set_character change the characterset of ALL dbs?

Post by g_p »

Hello,

i use php and mysql together.
i would like to modify the character set of a SPECIFIC database.

i do :

Code: Select all

if (USE_PCONNECT == 'true') {
      
     $$link = mysql_pconnect($server, $username, $password);                
     mysql_set_charset('utf8',$$link);  

    } else {
           $$link = mysql_connect($server, $username, $password);       
           mysql_set_charset('utf8',$$link);
    }
is the previous code going to change the character set of ALL the databases??
cause in the following link for mysql_set_character http://php.net/manual/en/function.mysql-set-charset.php
in the user contribution,in second contribution a user says :

"Be careful when working with multiple databases via the same user/host that you specify "true" as the fourth argument to mysql_connect(), otherwise when you call this function it will set both db connections to the same character set."


so what shall i do in order not to modify the character sets of all databases?? and only change the one i want??

thanks, in advance!
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Does mysql_set_character change the characterset of ALL

Post by Eran »

reading comprehension - "... it will set both db connections to ..."
mysql_set_charset() affects the connection only, not the database. If you are using the same connection to access multiple databases, it will retain the charset you defined
g_p
Forum Newbie
Posts: 13
Joined: Sun Jan 25, 2009 9:49 am

Re: Does mysql_set_character change the characterset of ALL

Post by g_p »

thanks for replying,
the code i've posted is from oscommerce (i'm testing that online shop at the moment)
and i wanted to be sure that this line

Code: Select all

mysql_set_charset('utf8',$$link);
is NOT going to affect the other databases.
Well the code for oscommerce (as i have understood) uses only ONE database for the store,not multiple ones.

1. So, only connection character set of the store db is going to change, right??
2. i was thinking of using these lines instead of mysql_set_character

Code: Select all

mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8"); 
Do these lines affect other databases, or no??

3 . Also, these lines affect server,results,databases or something else??

Thanks, in advance
Post Reply