New function to calculate rows

This commit is contained in:
Michael 2017-04-24 20:32:35 +00:00
parent d67338a895
commit 9959da5a1c
1 changed files with 23 additions and 4 deletions

View File

@ -587,6 +587,7 @@ class dba {
// Is mysqlnd installed?
$retval = $stmt->get_result();
} else {
$stmt->store_result();
$retval = $stmt;
}
break;
@ -676,7 +677,7 @@ class dba {
if (is_bool($stmt)) {
$retval = $stmt;
} else {
$retval = is_array(self::fetch($stmt));
$retval = (self::rows($stmt) > 0);
}
self::close($stmt);
@ -684,6 +685,24 @@ class dba {
return $retval;
}
/**
* @brief Returnr the number of rows of a statement
*
* @param object Statement object
* @return int Number of rows
*/
static public function rows($stmt) {
switch (self::$dbo->driver) {
case 'pdo':
return $stmt->rowCount();
case 'mysqli':
return $stmt->num_rows;
case 'mysql':
return mysql_num_rows($stmt);
}
return 0;
}
/**
* @brief Fetch a single row
*
@ -726,11 +745,11 @@ class dba {
// We need to get the field names for the array keys
// It seems that there is no better way to do this.
$result = $stmt->result_metadata();
$fields = $result->fetch_fields();
$columns = array();
foreach ($cols_num AS $col) {
$field = $result->fetch_field();
$columns[$field->name] = $col;
foreach ($cols_num AS $param => $col) {
$columns[$fields[$param]->name] = $col;
}
return $columns;
case 'mysql':