Commit a1f9cadd authored by Alex Facciorusso's avatar Alex Facciorusso

Added “has” helper method + doc in readme.md. Fixed closing php tag.

parent b4bd4cdc
......@@ -250,7 +250,7 @@ class MysqliDb
$columns = '*';
$column = is_array($columns) ? implode(', ', $columns) : $columns;
$this->_query = "SELECT $column FROM " .self::$_prefix . $tableName;
$this->_query = "SELECT $column FROM " . self::$_prefix . $tableName;
$stmt = $this->_buildQuery($numRows);
if ($this->isSubQuery)
......@@ -304,6 +304,20 @@ class MysqliDb
return ($stmt->affected_rows > 0 ? $stmt->insert_id : false);
}
/**
* A convenient function that returns TRUE if exists at least an element that
* satisfy the where condition specified calling the "where" method before this one.
*
* @param string $tableName The name of the database table to work with.
*
* @return array Contains the returned rows from the select query.
*/
public function has($tableName)
{
$this->getOne($tableName, '1');
return $this->count >= 1;
}
/**
* Update query. Be sure to first call the "where" method.
*
......@@ -1058,3 +1072,4 @@ class MysqliDb
$this->rollback ();
}
} // END class
?>
\ No newline at end of file
......@@ -15,6 +15,7 @@ MysqliDb -- Simple MySQLi wrapper with prepared statements
**[Joining Tables](#join-method)**
**[Subqueries](#subqueries)**
**[EXISTS / NOT EXISTS condition](#exists--not-exists-condition)**
**[Has method](#has-method)**
**[Helper Functions](#helper-commands)**
**[Transaction Helpers](#transaction-helpers)**
......@@ -328,6 +329,18 @@ $products = $db->get ("products");
// Gives SELECT * FROM products WHERE EXISTS (select userId from users where company='testCompany')
```
### Has method
A convenient function that returns TRUE if exists at least an element that satisfy the where condition specified calling the "where" method before this one.
```php
$db->where("user", $user);
$db->where("password", md5($password));
if($db->has("users")) {
return "You are logged";
} else {
return "Wrong user/password";
}
```
### Helper commands
Reconnect in case mysql connection died
```php
......
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