diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index c38db8f9c99..e3e0491b298 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -300,11 +300,13 @@ abstract class DoliDB implements Database /** - * return first result value from query + * Return first result value from query + * Note : This method executes a given SQL query and retrieves the first value of the first row of results. It should only be used with SELECT queries. + * Dont add LIMIT to your query, it will be added by this method * @param string $sql the sql query string * @return bool| var */ - public function getvalue($sql) + public function getValue($sql) { $sql .= ' LIMIT 1;'; @@ -319,9 +321,11 @@ abstract class DoliDB implements Database } /** - * return first result from query as object + * Return first result from query as object + * Note : This method executes a given SQL query and retrieves the first row of results as an object. It should only be used with SELECT queries + * Dont add LIMIT to your query, it will be added by this method * @param string $sql the sql query string - * @return bool| var + * @return bool| object */ public function getRow($sql) { @@ -335,4 +339,28 @@ abstract class DoliDB implements Database return false; } + + /** + * return all results from query as an array of objects + * Note : This method executes a given SQL query and retrieves all row of results as an array of objects. It should only be used with SELECT queries + * be carefull with this method use it only with some limit of results to avoid performences loss + * @param string $sql the sql query string + * @return bool| array + */ + public function getRows($sql) + { + $res = $this->query($sql); + if ($res) + { + $results = array(); + if($this->num_rows($res) > 0){ + while ($obj = $this->fetch_object($res)){ + $results[] = $obj; + } + } + return $results; + } + + return false; + } }