Thanks for your response. I've added the JSON_EXTRACT function as a custom dialect. When I run the following, I don't get an error, but just an empty array. I would have expected an error at least. Any insight at all is much appreciated?
$mysqlSettings['host'] = 'xxx';
$mysqlSettings['port'] = 'xxx';
$mysqlSettings['password'] = 'xxx'
$mysqlSettings['username'] = 'xxx';
$mysqlSettings['dbname'] = 'xxx';
$mysqlSettings['options'] = [
\PDO::ATTR_EMULATE_PREPARES => false,
\PDO::ATTR_STRINGIFY_FETCHES => false,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
];
$dialect = new \Phalcon\Db\Dialect\MySQL();
$dialect->registerCustomFunction(
'JSON_EXTRACT',
function($dialect, $expression) {
$arguments = $expression['arguments'];
return sprintf(
"JSON_EXTRACT(%s, %s)",
$dialect->getSqlExpression($arguments[0]),
$dialect->getSqlExpression($arguments[1])
);
}
);
$mysqlSettings['dialectClass'] = $dialect;
$db = new \Phalcon\Db\Adapter\Pdo\Mysql($mysqlSettings);
print_r($db->fetchAll("SELECT JSON_EXTRACT('[10, 20, [30, 40]]', '$[1]');")); // from mysql docs