I am storing some data inside mysql
using the JSON
Type field. When I try to select query my json data field in Laravel 5.6, I get an exception
$transactions = DB::table('transactions')
->select('transactions.uuids_json', '... other columns')
....
SQLSTATE[HY000]: General error: 2036, query exception
If I remove the uuids_json
field, everything works normal. Do I have to somehow use raw statements or something?
The column uuid_json
data field contains rows like this:
["1a7b29b8-5009-4266-8192-508930f2f92a", "3d52cfd5-d3c0-467f-8da1-cf81c344ad20", "cbe6e7fb-d806-49e2-8616-3c28afa012fe", "dfda9df5-2cbf-4cb8-aa54-a6dc23f73995"]
Thank you for any help!
This sounds related to https://bugs.php.net/bug.php?id=70384
Make sure your PHP install is using the mysqlnd 5.0.11 or later, which according to that bug log should include the fix.
Check php -i
or phpinfo()
for the version of mysqlnd you use.
If you can't upgrade to a version of the library that supports the JSON data type, a workaround is to CAST the JSON column to a string:
->select(\DB::raw("CAST(transactions.uuids_json as CHAR) as uuids_json"), ...)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.