|
|
|
@ -56,7 +56,7 @@ class ActiveQuery extends \yii\base\Component implements ActiveQueryInterface
|
|
|
|
|
* Executes the query and returns all results as an array. |
|
|
|
|
* @param Connection $db the database connection used to execute the query. |
|
|
|
|
* If this parameter is not given, the `db` application component will be used. |
|
|
|
|
* @return ActiveRecord[] the query results. If the query results in nothing, an empty array will be returned. |
|
|
|
|
* @return array|ActiveRecord[] the query results. If the query results in nothing, an empty array will be returned. |
|
|
|
|
*/ |
|
|
|
|
public function all($db = null) |
|
|
|
|
{ |
|
|
|
@ -215,20 +215,20 @@ class ActiveQuery extends \yii\base\Component implements ActiveQueryInterface
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the query result as a scalar value. |
|
|
|
|
* The value returned will be the first column in the first row of the query results. |
|
|
|
|
* @param string $column name of the column to select |
|
|
|
|
* The value returned will be the specified attribute in the first record of the query results. |
|
|
|
|
* @param string $attribute name of the attribute to select |
|
|
|
|
* @param Connection $db the database connection used to execute the query. |
|
|
|
|
* If this parameter is not given, the `db` application component will be used. |
|
|
|
|
* @return string|boolean the value of the first column in the first row of the query result. |
|
|
|
|
* False is returned if the query result is empty. |
|
|
|
|
* @return string the value of the specified attribute in the first record of the query result. |
|
|
|
|
* Null is returned if the query result is empty. |
|
|
|
|
*/ |
|
|
|
|
public function scalar($column, $db = null) |
|
|
|
|
public function scalar($attribute, $db = null) |
|
|
|
|
{ |
|
|
|
|
$record = $this->one($db); |
|
|
|
|
if ($record === null) { |
|
|
|
|
return false; |
|
|
|
|
if ($record !== null) { |
|
|
|
|
return $record->$attribute; |
|
|
|
|
} else { |
|
|
|
|
return $record->$column; |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|