You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Query binding fails when using date_format with hours in it (colon issue)
If there is a colon in the query, the query builder thinks it is a named bind, and handles the query in that way, even if you have ? bindings.
CodeIgniter 4 version
v4.1.1
Affected module(s)
system/Database/Query.php
Line 352
Expected behavior, and steps to reproduce if appropriate
Old version: $hasNamedBinds = strpos($sql, ':') !== false && strpos($sql, ':=') === false;
This returns true when query has date_format(now(), '%d-%m-%Y %H:%i'), but in the query I only use ? as binding, so it won't find any :mybind: binding.
Describe the bug
Query binding fails when using date_format with hours in it (colon issue)
If there is a colon in the query, the query builder thinks it is a named bind, and handles the query in that way, even if you have ? bindings.
CodeIgniter 4 version
v4.1.1
Affected module(s)
system/Database/Query.php
Line 352
Expected behavior, and steps to reproduce if appropriate
Old version:
$hasNamedBinds = strpos($sql, ':') !== false && strpos($sql, ':=') === false;
This returns true when query has
date_format(now(), '%d-%m-%Y %H:%i')
, but in the query I only use ? as binding, so it won't find any :mybind: binding.suggestion:
$hasNamedBinds = preg_match('/:[a-z._-]+:/',$sql);
With this fix, all my queries are working.
Context
The text was updated successfully, but these errors were encountered: