本文整理汇总了PHP中yii\db\Query::one方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::one方法的具体用法?PHP Query::one怎么用?PHP Query::one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\Query
的用法示例。
在下文中一共展示了Query::one方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mostPopular
public static function mostPopular()
{
$query = new Query();
$query->select('meme_id, COUNT(meme_id) AS n_memes')->from('meme_vidmage')->groupBy('meme_id')->orderBy(['n_memes' => SORT_DESC])->limit(1);
$row = $query->one();
return self::findOne($row['meme_id']);
}
示例2: Auth
public function Auth($username = null)
{
$db = new Query();
$db->select("*")->from("masuser")->where("username = '{$username}' ")->limit("1");
$rows = $db->one();
return $rows;
}
示例3: actionIndex
public function actionIndex($id)
{
$session = \Yii::$app->session;
$request = \Yii::$app->request;
$donateForm = new DonateForm();
$buyForm = new BuyForm();
$supportForm = new SupportForm();
if ($donateForm->load($request->post()) && $donateForm->submit()) {
$session->set('donate', $request->post('DonateForm'));
return $this->redirect('@web/index.php?r=support/donate');
} else {
if ($buyForm->load($request->post()) && $buyForm->submit()) {
$session->set('bought', $request->post('BuyForm'));
return $this->redirect('@web/index.php?r=support/buy');
} else {
if ($supportForm->load($request->post()) && $supportForm->submit()) {
$session->set('motive', $request->post('SupportForm'));
return $this->redirect('@web/index.php?r=support/motivation');
}
}
}
$query = new Query();
// compose the query
$query->from('hero')->where('Hid=:id', array(':id' => $id));
$hero = $query->one();
$session->set('hero', $hero);
return $this->render('support', array('hero' => $hero));
}
示例4: Edit
public function Edit($id_apteka, $id_preparat)
{
$query = new Query();
$query->from('preparats_ansver');
$query->where(['=', 'id_apteka', $id_apteka]);
$query->andWhere(['=', 'id_o', $id_preparat]);
return $query->one();
}
示例5: GetItem
public function GetItem($id = 0)
{
$query = new Query();
$query->from($this->table);
$query->where(["id" => $id]);
$result = $query->one();
return $result;
}
示例6: actionSuccess
public function actionSuccess($id)
{
$query = new Query();
// compose the query
$query->from('event')->where('Eid=:id', array(':id' => $id));
// build and execute the query
$detail = $query->one();
return $this->render('success', array('detail' => $detail));
}
示例7: GetTableForModel
public function GetTableForModel($module_name = "")
{
if (!empty($module_name)) {
$_module_name = strtolower($module_name);
$query = new Query();
$query->select('db.name')->from("backend__id_db as db")->join('LEFT JOIN', "module as m", "m.name = '{$_module_name}'")->where("m.model = db.model_id");
$result = $query->one();
return $result["name"];
}
}
示例8: actionProfile
public function actionProfile($id)
{
$query = new Query();
// compose the query
$query->from('hero')->where('Hid=:id', array(':id' => $id));
$hero = $query->one();
$q = new Query();
$q->from('takespart')->innerJoin('event', 'takespart.EventId=event.Eid')->where('HeroId=:id', array(':id' => $id));
$event = $q->one();
return $this->render('profile', array('hero' => $hero, 'event' => $event));
}
示例9: PageContentForCheck
public function PageContentForCheck($type_page = 0)
{
list($module, $controller, $action) = explode("/", yii::$app->request->pathInfo);
$query = new Query();
$query->select("COUNT(p.id) as count")->innerJoin("module as m", "m.id = p.module and m.name = '{$module}'")->from("backend__pages as p")->where("p.id = {$type_page}");
$result = $query->one();
if ($result["count"] == 1) {
return true;
} else {
return false;
}
}
示例10: actionIndex
public function actionIndex($id)
{
$session = \Yii::$app->session;
$request = \Yii::$app->request;
$challengeForm = new ChallengeForm();
if ($challengeForm->load($request->post()) && $challengeForm->submit()) {
$session->set('dump', $request->post('ChallengeForm'));
return $this->redirect('@web/index.php?r=site/dump');
} else {
$query = new Query();
// compose the query
$query->from('hero')->where('Hid=:id', array(':id' => $id));
$hero = $query->one();
return $this->render('challenge', ['challengeForm' => $challengeForm, 'hero' => $hero]);
}
}
示例11: up
public function up()
{
$people_to_city = ['Маша' => [1, 2], 'Ваня' => [1, 2, 3, 4, 5], 'Оля' => [4, 5], 'Женя' => [2, 3], 'Вася' => [], 'Коля' => [6], 'Олег' => [3]];
foreach ($people_to_city as $name => $cities) {
$query = new Query();
// compose the query
$query->select('id')->from('people');
$query->andFilterWhere(['like', 'name', $name]);
$row = $query->one();
var_dump($row);
if (!empty($cities)) {
foreach ($cities as $cityId) {
$this->insert('people_city', ['people_id' => $row['id'], 'city_id' => $cityId]);
}
}
}
}
示例12: get
/**
* Validate a client
*
* @param string $clientId The client's ID
* @param string $clientSecret The client's secret (default = "null")
* @param string $redirectUri The client's redirect URI (default = "null")
* @param string $grantType The grant type used (default = "null")
*
* @return \League\OAuth2\Server\Entity\ClientEntity
*/
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null)
{
$client = null;
$selectTargets = "{{%oauth_clients}}.id, {{%oauth_clients}}.name";
if ($redirectUri !== null && is_string($redirectUri) && strlen($redirectUri) > 0) {
$selectTargets = "{{%oauth_clients}}.*, {{%oauth_client_redirect_uris}}.*";
}
$clientStorageQueryBuilder = new Query();
$clientStorageQueryBuilder->select($selectTargets)->from("{{%oauth_clients}}")->where("{{%oauth_clients}}.id=:oauth_client_id AND {{%oauth_clients}}.secret=:oauth_client_secret_where", [":oauth_client_id" => $clientId, ":oauth_client_secret_where" => $clientSecret]);
/**
* Regarding oauth_client_redirect_uris:
* You may or may not have this table. If you don't, and don't need it , as described in the league docs for each grant,
* you won't really pass this condition, and that's why it's implemented this way
*/
if ($redirectUri !== null && is_string($redirectUri) && strlen($redirectUri) > 0) {
$clientStorageQueryBuilder->innerJoin("{{%oauth_client_redirect_uris}}", "{{%oauth_clients}}.id = {{%oauth_client_redirect_uris}}.client_id")->where(["{{%oauth_client_redirect_uris}}.redirect_uri" => $redirectUri]);
}
$clientStorageResult = $clientStorageQueryBuilder->one();
if (isset($clientStorageResult['id']) && isset($clientStorageResult['name'])) {
$client = (new ClientEntity($this->getServer()))->hydrate(["id" => $clientStorageResult["id"], "name" => $clientStorageResult["name"]]);
}
return $client;
}
示例13: Query
}
echo '<tr class="bgdark">
<td class="bgdark"></td>
<td class="bgdark"></td>
<td class="bgdark"></td>
<td class="bgdark"></td>
<td class="bgdark"><div class="price">' . app\components\NumericLib::indoStyle($debit, 0, ',', '.') . '</div></td>
<td class="bgdark"><div class="price">' . app\components\NumericLib::indoStyle($credit, 0, ',', '.') . '</div></td>
<td class="bgdark"></td>
</tr>';
}
} else {
echo '<tr>';
$accquery = new Query();
$accquery->select('code , name')->from('account_account')->where(['id' => $account]);
$res = $accquery->one();
echo '<td>' . $res['code'] . '</td>';
echo '<td colspan="6">' . $res['name'] . '</td>';
echo '</tr>';
$queryline = new Query();
$queryline->select('aml.ref as ref, aml.name as name ,aml.date as date, aml.debit as debit, aml.credit as credit')->from('account_move_line aml')->join('LEFT JOIN', 'account_move as am', 'am.id=aml.move_id')->where(['>=', 'aml.date', $from])->andWhere(['<=', 'aml.date', $to])->andWhere(['am.state' => 'posted'])->andWhere(['aml.account_id' => $account])->addOrderBy(['aml.date' => SORT_ASC]);
$lines = $queryline->all();
$debit = 0;
$credit = 0;
foreach ($lines as $line) {
echo '<tr>
<td></td>
<td>' . $line['name'] . '</td>
<td>' . Yii::$app->formatter->asDatetime($line['date'], "php:d-m-Y") . '</td>
<td>' . $line['ref'] . '</td>
<td><div class="price">' . app\components\NumericLib::indoStyle($line['debit'], 0, ',', '.') . '</div></td>
示例14: beforeSave
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->parent === null || $this->parent->isNewRecord) {
$this->level = 0;
} else {
$this->level = $this->parent->level + 1;
}
if ($this->isNewRecord) {
$query = new Query();
$query->select(['position']);
$query->from(self::tableName());
$query->orderBy('position DESC');
if ($this->parent_id) {
$query->where('parent_id=:parent_id');
$query->params([':parent_id' => $this->parent_id]);
} else {
$query->where('parent_id is NULL');
}
$last = $query->one();
$this->position = $last ? $last['position'] + 1 : 0;
}
return true;
} else {
return false;
}
}
示例15: beforeSave
public function beforeSave($insert)
{
if (!parent::beforeSave($insert)) {
return false;
}
$query = new Query();
$query->select('COUNT(*)')->where(['post_id' => $this->post_id])->from(static::tableName());
$count = $query->scalar(static::getDb());
if ($count == 0) {
$this->left = 1;
$this->right = 2;
$this->level = 1;
} else {
if (empty($this->parent_id)) {
$query = new Query();
$query->select('MAX({{right}})')->where(['post_id' => $this->post_id])->from(static::tableName());
$maxRight = $query->scalar(static::getDb());
$this->left = $maxRight + 1;
$this->right = $maxRight + 2;
$this->level = 1;
} else {
/*$query = new Query();
$query
->select(['{{left}} left', '{{level}} level'])
->where(['post_id' => $this->post_id, 'id' => $this->parent_id])
->from(static::tableName());
$data1 = $query->all(static::getDb());
static::getDb()
->createCommand('UPDATE ' . static::tableName() . ' SET {{right}} = {{right}} + 2 WHERE {{right}} > :left')
->bindValue(':left', $data1[0]['left'])
->execute();
static::getDb()
->createCommand('UPDATE ' . static::tableName() . ' SET {{left}} = {{left}} + 2 WHERE {{left}} > :left')
->bindValue(':left', $data1[0]['left'])
->execute();
$this->left = $data1[0]['left'] + 1;
$this->right = $data1[0]['left'] + 2;
$this->level = $data1[0]['level'] + 1;*/
$query = new Query();
$query->select(['id', '{{left}} left', '{{right}} right', '{{level}} level'])->where(['post_id' => $this->post_id, 'id' => $this->parent_id])->from(static::tableName());
$data1 = $query->all(static::getDb());
if ($data1[0]['left'] != $data1[0]['right'] - 1) {
$query = new Query();
$query->select(['id', '{{left}} left', '{{right}} right', '{{level}} level', '{{text}}'])->where(['post_id' => $this->post_id, 'level' => $data1[0]['level']])->andWhere('{{left}} > :r AND {{id}} != :id', [':r' => $data1[0]['right'], ':id' => $data1[0]['id']])->from(static::tableName());
$data2 = $query->one(static::getDb());
static::getDb()->createCommand('UPDATE ' . static::tableName() . ' SET {{right}} = {{right}} + 2 WHERE {{right}} > :left')->bindValue(':left', $data2['left'] - 2)->execute();
static::getDb()->createCommand('UPDATE ' . static::tableName() . ' SET {{left}} = {{left}} + 2 WHERE {{left}} > :left')->bindValue(':left', $data2['left'] - 2)->execute();
$this->left = $data2['right'] - 2;
$this->right = $data2['right'] - 1;
$this->level = $data1[0]['level'] + 1;
} else {
static::getDb()->createCommand('UPDATE ' . static::tableName() . ' SET {{right}} = {{right}} + 2 WHERE {{right}} > :left')->bindValue(':left', $data1[0]['left'])->execute();
static::getDb()->createCommand('UPDATE ' . static::tableName() . ' SET {{left}} = {{left}} + 2 WHERE {{left}} > :left')->bindValue(':left', $data1[0]['left'])->execute();
$this->left = $data1[0]['left'] + 1;
$this->right = $data1[0]['left'] + 2;
$this->level = $data1[0]['level'] + 1;
}
}
}
return true;
}