From ffef68ba3a2555ee2d1014ddf1baa735475768b1 Mon Sep 17 00:00:00 2001 From: Dmitry Kolosov Date: Mon, 14 Oct 2019 09:55:25 +0300 Subject: [PATCH] [Db] fix grabFromDatabase description in docs (#5717) --- docs/modules/Db.md | 16 +++++++++++++--- src/Codeception/Module/Db.php | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/docs/modules/Db.md b/docs/modules/Db.md index a9d60cc481..d91ca566c1 100644 --- a/docs/modules/Db.md +++ b/docs/modules/Db.md @@ -271,18 +271,28 @@ $mails = $I->grabColumnFromDatabase('users', 'email', array('name' => 'RebOOter' ### grabFromDatabase -Fetches all values from the column in database. +Fetches a single column value from a database. Provide table name, desired column and criteria. ``` php grabFromDatabase('users', 'email', array('name' => 'RebOOter')); +$mail = $I->grabFromDatabase('users', 'email', array('name' => 'Davert')); +``` +Comparison expressions can be used as well: + +``` php +grabFromDatabase('posts', ['num_comments >=' => 100]); +$user = $I->grabFromDatabase('users', ['email like' => 'miles%']); ``` +Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * `param string` $table * `param string` $column * `param array` $criteria - + + * `return` mixed Returns a single column value or false ### grabNumRecords diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index 84a8825906..0fe35d2787 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -883,19 +883,28 @@ public function grabColumnFromDatabase($table, $column, array $criteria = []) } /** - * Fetches all values from the column in database. + * Fetches a single column value from a database. * Provide table name, desired column and criteria. * * ``` php * grabFromDatabase('users', 'email', array('name' => 'RebOOter')); + * $mail = $I->grabFromDatabase('users', 'email', array('name' => 'Davert')); + * ``` + * Comparison expressions can be used as well: + * + * ```php + * grabFromDatabase('posts', ['num_comments >=' => 100]); + * $user = $I->grabFromDatabase('users', ['email like' => 'miles%']); * ``` * + * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. + * * @param string $table * @param string $column - * @param array $criteria + * @param array $criteria * - * @return mixed + * @return mixed Returns a single column value or false */ public function grabFromDatabase($table, $column, $criteria = []) {