问题描述
我正在mysql 5.7上尝试新的json数据类型.当我使用本机php mysql查询时,它工作正常,但是当我使用PDO查询数据时,它显示此错误:
I'm trying new json datatype on mysql 5.7. When I use native php mysql query, it works fine, but when I use PDO to query data, it shows this error:
你们知道如何解决这个问题吗?
Do you guys know how to solve this problem ?
谢谢.
使用我的简单测试代码进行更新:
Update with my simple test code:
<?php
try{
$db = new PDO('mysql:host=some.host;dbname=somedb;charset=utf8', 'user', 'pwd');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}catch(PDOException $e){
echo "Error1: ".$e;
}
try{
$query = $db->query("select * from table_with_json_type");
}catch(PDOException $e){
echo "Error2: ".$e;
}
?>
推荐答案
这是向PHP开发人员报告的错误#70384
It's a Bug reported to PHP Developers #70384
开发者[email protected]刚刚发布:
The developer [email protected] just posted:
源快照每三个小时打包一次;这个变化 将在下一个快照中.您可以在以下位置获取快照 http://snaps.php.net/.
Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/.
对于Windows:
http://windows.php.net/snapshots/感谢您的报告,以及为了 帮助我们改善PHP.
http://windows.php.net/snapshots/ Thank you for the report, and for helping us make PHP better.
已在PHP-5.6.19,PHP-7.0和主版(PHP-7.1)中修复
Fixed in PHP-5.6.19, PHP-7.0 and master (PHP-7.1)
感谢您的举报
因此,PHP 5.6.19+将支持JSON数据类型对于其他版本,上面提供了一种解决方法.
So, the JSON data type will be supported on PHP 5.6.19+For other version there is a workaround available above.
此解决方法将具有CAST功能的JSON字段修改为CHAR,从PHP的角度来看,这很好:例如:
This workaround modify the JSON field with CAST feature to a CHAR, which is fine from PHP's perspective:Eg.:
select *, CAST(json_col as CHAR) as json_col from table_with_json_type
在所有情况下都对我有用.
It's worked to me in all cases.
要完全兼容,您必须使用PHP-5.6.19 +
To Full compatibility you must use PHP-5.6.19+
这篇关于表格上的PHP PDO查询错误具有json数据类型(MySQL 5.7.8-rc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!