Commit 7133f129 authored by Alexander Butenko's avatar Alexander Butenko

Added count variable which stores returned rows count

parent 009cd11a
...@@ -68,6 +68,12 @@ class MysqliDb ...@@ -68,6 +68,12 @@ class MysqliDb
* @var array * @var array
*/ */
protected $_bindParams = array(''); // Create the empty 0 index protected $_bindParams = array(''); // Create the empty 0 index
/**
* Variable which holds an amount of returned rows during get/getOne/select queries
*
* @var string
*/
public $count = 0;
/** /**
* @param string $host * @param string $host
...@@ -118,6 +124,7 @@ class MysqliDb ...@@ -118,6 +124,7 @@ class MysqliDb
$this->_query = null; $this->_query = null;
$this->_whereTypeList = null; $this->_whereTypeList = null;
$this->_paramTypeList = null; $this->_paramTypeList = null;
$this->count = 0;
} }
/** /**
...@@ -615,6 +622,8 @@ class MysqliDb ...@@ -615,6 +622,8 @@ class MysqliDb
} }
array_push($results, $x); array_push($results, $x);
} }
$this->count = $stmt->num_rows;
return $results; return $results;
} }
......
...@@ -30,7 +30,8 @@ if($id) ...@@ -30,7 +30,8 @@ if($id)
``` ```
### Select Query ### Select Query
After any select/get function calls amount or returned rows
is stored in $count variable
```php ```php
$users = $db->get('users'); //contains an array of all users $users = $db->get('users'); //contains an array of all users
$users = $db->get('users', 10); //contains an array 10 users $users = $db->get('users', 10); //contains an array 10 users
...@@ -44,9 +45,10 @@ echo "total ".$stats['cnt']. "users found"; ...@@ -44,9 +45,10 @@ echo "total ".$stats['cnt']. "users found";
$cols = Array ("id, name, email"); $cols = Array ("id, name, email");
$users = $db->get ("users", null, $cols); $users = $db->get ("users", null, $cols);
foreach ($users as $user) { if ($db->count > 0)
foreach ($users as $user) {
print_r ($user); print_r ($user);
} }
``` ```
or select just one row or select just one row
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment