发现插入的
,数据库报1366错误。
解决方案如下:
VIM /etc/my.cnf
[mysql]
default-character-set=utf8
[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8
init_connect='SET NAMES utf8'
DB脚本:
create database news charset utf8;
CREATE TABLE `news` (
`id` int(11) DEFAULT NULL,
`details` varchar(8192) CHARACTER SET utf8mb4 DEFAULT '',
) ENGINE=MyISAM DEFAULT CHARSET=utf8
PHP连接时使用下面的SQL
Class DbUtil {
private static $db;
private static $host='127.0.0.1';
private static $user='root';
private static $pass='xxxx';
private static $dbname='xxxx';
private static $instance = null;
function __construct()
{
$this->dbInit();
}
function dbInit()
{
if(!self::$db)
{
self::$db=new mysqli(self::$host,self::$user,self::$pass,self::$dbname);
if (self::$db->connect_errno)
{
die("Connect failed: %s\n", self::$db->connect_error);
}
self::$db->set_charset("utf8mb64");
}
}
public static function getInstance(){
if(self::$instance==null){
self::$instance=new DbUtil();
}
return self::$db;
}
}