From b19fa729bf42b9b3ae266432ec0b3b903b3bec53 Mon Sep 17 00:00:00 2001 From: Dylan Wagstaff Date: Mon, 21 Oct 2024 16:06:58 +1300 Subject: [PATCH] ENH spread MySQL ORM bind parameters Because the rest of the "bit of hackery" is now unnecessary The ORM rewrite supporting parameterised queries was merged in July 2014 d8e9af8af8d59b3ee16f404f2f2b0a528d503022 and relased in October 2015. https://github.com/silverstripe/silverstripe-framework/releases/tag/3.2.0 The official PHP support at the time was 5.3.2+ https://web.archive.org/web/20140616033159/http://www.silverstripe.org/system-requirements Which excluded the spread operator introduce in PHP 5.6 from being used. https://www.php.net/manual/en/migration56.new-features.php#migration56.new-features.splat Ten years later none of this is relevant anymore, so we can save some useless data shuffling from every parameterised query by just directly using the spread operator. --- src/ORM/Connect/MySQLiConnector.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/ORM/Connect/MySQLiConnector.php b/src/ORM/Connect/MySQLiConnector.php index e480f5db9bf..98d2b239bd5 100644 --- a/src/ORM/Connect/MySQLiConnector.php +++ b/src/ORM/Connect/MySQLiConnector.php @@ -278,16 +278,7 @@ public function parsePreparedParameters($parameters, &$blobs) */ public function bindParameters(mysqli_stmt $statement, array $parameters) { - // Because mysqli_stmt::bind_param arguments must be passed by reference - // we need to do a bit of hackery - $boundNames = []; - $parametersCount = count($parameters ?? []); - for ($i = 0; $i < $parametersCount; $i++) { - $boundName = "param$i"; - $$boundName = $parameters[$i]; - $boundNames[] = &$$boundName; - } - $statement->bind_param(...$boundNames); + $statement->bind_param(...$parameters); } public function preparedQuery($sql, $parameters, $errorLevel = E_USER_ERROR)