diff --git a/common/framework/db.php b/common/framework/db.php index 6666756fd..a081d2c20 100644 --- a/common/framework/db.php +++ b/common/framework/db.php @@ -223,9 +223,10 @@ class DB * @param array $args * @param array $columns * @param string $result_type + * @param string $result_class * @return \BaseObject */ - public function executeQuery(string $query_id, $args = [], $column_list = [], $result_type = 'auto'): \BaseObject + public function executeQuery(string $query_id, $args = [], $column_list = [], $result_type = 'auto', $result_class = ''): \BaseObject { // Validate the args. if (is_object($args)) @@ -363,7 +364,7 @@ class DB } elseif ($query->type === 'SELECT') { - $result = $this->_fetch($this->_last_stmt, $last_index, $result_type); + $result = $this->_fetch($this->_last_stmt, $last_index, $result_type, $result_class); } else { @@ -506,9 +507,10 @@ class DB * @param \PDOStatement $stmt * @param int $last_index * @param string $result_type + * @param string $result_class * @return mixed */ - public function _fetch($stmt, $last_index = 0, $result_type = 'auto') + public function _fetch($stmt, $last_index = 0, $result_type = 'auto', $result_class = '') { if (!($stmt instanceof \PDOStatement)) { @@ -525,7 +527,7 @@ class DB $index = $last_index; $step = $last_index !== 0 ? -1 : 1; - while ($row = $stmt->fetchObject()) + while ($row = $stmt->fetchObject($result_class ?: 'stdClass')) { $result[$index] = $row; $index += $step; diff --git a/common/legacy.php b/common/legacy.php index c020bd0cc..3ea7fb604 100644 --- a/common/legacy.php +++ b/common/legacy.php @@ -137,12 +137,13 @@ function getClass($module_name) * @param array|object $args Arguments * @param array $column_list Column list * @param string $result_type 'auto', 'array' or 'raw' + * @param string $result_class Name of class to use instead of stdClass * @return object Query result data */ -function executeQuery($query_id, $args = [], $column_list = [], $result_type = 'auto') +function executeQuery($query_id, $args = [], $column_list = [], $result_type = 'auto', $result_class = 'stdClass') { $oDB = Rhymix\Framework\DB::getInstance(); - return $oDB->executeQuery($query_id, $args, $column_list, $result_type); + return $oDB->executeQuery($query_id, $args, $column_list, $result_type, $result_class); } /** @@ -152,12 +153,13 @@ function executeQuery($query_id, $args = [], $column_list = [], $result_type = ' * @param string $query_id (module name.query XML file) * @param array|object $args Arguments * @param array $column_list Column list + * @param string $result_class Name of class to use instead of stdClass * @return object Query result data */ -function executeQueryArray($query_id, $args = [], $column_list = []) +function executeQueryArray($query_id, $args = [], $column_list = [], $result_class = 'stdClass') { $oDB = Rhymix\Framework\DB::getInstance(); - return $oDB->executeQuery($query_id, $args, $column_list, 'array'); + return $oDB->executeQuery($query_id, $args, $column_list, 'array', $result_class); } /**