Commit ef942d6b authored by Josh Campbell's avatar Josh Campbell

Merge pull request #183 from alexfacciorusso/master

Added “has” helper method, fixed closing php tag.
parents 9026a39c a1f9cadd
......@@ -267,7 +267,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)
......@@ -345,6 +345,20 @@ class MysqliDb
return true;
}
/**
* 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.
*
......@@ -1124,3 +1138,4 @@ class MysqliDb
$this->rollback ();
}
} // END class
?>
\ No newline at end of file
......@@ -14,7 +14,8 @@ MysqliDb -- Simple MySQLi wrapper with prepared statements
**[Properties Sharing](#properties-sharing)**
**[Joining Tables](#join-method)**
**[Subqueries](#subqueries)**
**[EXISTS / NOT EXISTS condition](#exists--not-exists-condition)**
**[EXISTS / NOT EXISTS condition](#exists--not-exists-condition)**
**[Has method](#has-method)**
**[Helper Functions](#helper-commands)**
**[Transaction Helpers](#transaction-helpers)**
......@@ -386,6 +387,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