# 兼容 php 7.2 及 mysql 8
[![](http://static.phpgrace.com/statics/images/video2.png)](https://ke.qq.com/course/310478)
**兼容 php 7.2**
php 7.2 废弃了 create\_function 函数,为了更好的兼容我们去除了 tool 方法;
请大家在自定义工具类时遵循命名空间,第三方工具类使用时手动 include 并遵循 \\ 顶级命名空间调用,如 :
~~~
$tool = new \xxxTool();
~~~
**兼容 mysql 8**
php 与 mysql 8 连接会报错 :
~~~
报错:PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers
~~~
原因 :
~~~
由于Mysql8.0将默认的字符集改为了utfmb4,因此和客户端(不仅仅是PHP)的通信无法识别,我们需要更改my.cnf来指定字符集。
~~~
解决方案 :
修改 mysql 8 配置 : my.ini 调整编码
~~~
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\mysql8
# 设置mysql数据库的数据的存放目录
datadir=D:\mysql8\Data
#忘记密码时使用
#skip-grant-tables
#设置协议认证方式(重点啊)
default_authentication_plugin=mysql_native_password
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
~~~
**\*\*\* graceCms 付费用户调整 \*\*\*
****1\. 打开 admin/controllers/ccode.php, 替换 函数内容**
~~~
public function fields(){
if(empty($this->gets[0])){$this->json('参数错误', 'error');}
$db = db($this->gets[0]);
$pdo = $db->pdo;
$sta = $pdo->prepare(
'select ORDINAL_POSITION,COLUMN_NAME ,DATA_TYPE, COLUMN_COMMENT
from information_schema.columns where table_schema = ? and table_name = ?
order by ORDINAL_POSITION asc');
$sta->execute(array(sc('db','dbname'), sc('db','pre').$this->gets[0]));
$fields = $sta->fetchAll(\PDO::FETCH_ASSOC);
if(empty($fields)){
$this->json('数据表名称错误', 'error');
}
$str = '';
$checkType = '
int
string
between
betweenD
betweenF
same
sameWith
notSame
phone
zipCode
reg
fun
';
foreach($fields as $field){
$str .= '
'.$field['COLUMN_NAME'].''.$checkType.'';}
$this->json($str, 'ok');
}
~~~
**2\. 打开 phpGrace.php 删除 tool 函数的定义;**