File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -363,6 +363,20 @@ public function insert($tableName, $insertData)
363363 return true ;
364364 }
365365
366+ /**
367+ * A convenient function that returns TRUE if exists at least an element that
368+ * satisfy the where condition specified calling the "where" method before this one.
369+ *
370+ * @param string $tableName The name of the database table to work with.
371+ *
372+ * @return array Contains the returned rows from the select query.
373+ */
374+ public function has ($ tableName )
375+ {
376+ $ this ->getOne ($ tableName , '1 ' );
377+ return $ this ->count >= 1 ;
378+ }
379+
366380 /**
367381 * Update query. Be sure to first call the "where" method.
368382 *
@@ -1153,3 +1167,4 @@ public function _transaction_status_check () {
11531167 $ this ->rollback ();
11541168 }
11551169} // END class
1170+ ?>
Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ MysqliDb -- Simple MySQLi wrapper with prepared statements
1414** [ Properties Sharing] ( #properties-sharing ) **
1515** [ Joining Tables] ( #join-method ) **
1616** [ Subqueries] ( #subqueries ) **
17- ** [ EXISTS / NOT EXISTS condition] ( #exists--not-exists-condition ) **
17+ ** [ EXISTS / NOT EXISTS condition] ( #exists--not-exists-condition ) **
18+ ** [ Has method] ( #has-method ) **
1819** [ Helper Functions] ( #helper-commands ) **
1920** [ Transaction Helpers] ( #transaction-helpers ) **
2021
@@ -393,6 +394,18 @@ $products = $db->get ("products");
393394// Gives SELECT * FROM products WHERE EXISTS (select userId from users where company='testCompany')
394395```
395396
397+ ### Has method
398+ 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.
399+ ``` php
400+ $db->where("user", $user);
401+ $db->where("password", md5($password));
402+ if($db->has("users")) {
403+ return "You are logged";
404+ } else {
405+ return "Wrong user/password";
406+ }
407+ ```
408+
396409### Helper commands
397410Reconnect in case mysql connection died
398411``` php
You can’t perform that action at this time.
0 commit comments