表格上的PHP PDO查询错误具有json数据类型(MySQL 5.7.8-rc) [英] PHP PDO query error on table has json data type (MySQL 5.7.8-rc)

查看:117
本文介绍了表格上的PHP PDO查询错误具有json数据类型(MySQL 5.7.8-rc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在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:

错误:/some_folder/pdo.php:12中消息'SQLSTATE [HY000]:常规错误:2036'的异常'PDOException'堆栈跟踪:#0/some_folder/pdo.php(12):PDO-> query (从table_has_json_datatype中选择*")#1 {main}

Error: exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2036 ' in /some_folder/pdo.php:12 Stack trace: #0 /some_folder/pdo.php(12): PDO->query('select * from table_has_json_datatype') #1 {main}

你们知道如何解决这个问题吗?

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开发人员报告的错误

It's a Bug reported to PHP Developers #70384

开发者andrey@php.net刚刚发布:

The developer andrey@php.net just posted:

此错误的修复已提交.

The fix for this bug has been committed.

源快照每三个小时打包一次;这个变化 将在下一个快照中.您可以在以下位置获取快照 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆