mysql5的字符集和sql mode成绩



作者: btchnia  出自: http://www.linuxdiyf.com
mysql5添加了一些新的结果的划定规则,其中对开源顺序影响比较大年夜的有两个,一个是4.0.12 入手下手的4层次字符集,一个是5.0.18入手下手的默许strict mode。

关于这两个成绩,效用最好的操持方案,便是间接批改my.ini

# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf8
#这里改成utf-8

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION"
#这里改成=""

当你没有权限进行批改时,就只幸而顺序中判别了,必须在每次衔接上数据库时进行设定。在把持了数据库笼统层的顺序中批改起来也很简单:

if(mysql_get_server_info( $connect ) > '4.0.1')
{
mysql_query( "set names 'utf8'" , $connect );
}

if(mysql_get_server_info( $connect ) > '5.0.1')
{
mysql_query("SET sql_mode=''" , $connect );
}




版权声明: 原创作品,容许转载,转载时请务必以超链接体式格局标明文章 原始来由 、作者信息和本声明。不然将追究功令责任。

原文地址:https://www.cnblogs.com/zgqjymx/p/1973559.html