Add getRows method and comments
This commit is contained in:
parent
09591d75f6
commit
395446a924
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user