gpt4 book ai didi

mysql - 如何在 Phalcon 中建立有条件的连接

转载 作者:行者123 更新时间:2023-11-29 06:35:49 24 4
gpt4 key购买 nike

我有以下 SQL:

SELECT  `settings`.*, `character_settings`.`value`
FROM `settings`
LEFT JOIN
`character_settings`
ON `character_settings`.`setting_id` = `settings`.`id`
AND `character_settings`.`character_id` = '1'

如何使用 Phalcon CreateBuilder() 重写相同的查询?

最佳答案

尝试这样的事情:

$rows = $this->modelsManager
->createBuilder()
->columns(array('Settings.*', 'CharacterSettings.value as char_value'))
->from('Settings')
->leftJoin('CharacterSettings', 'Settings.id = CharacterSettings.setting_id AND CharacterSettings.character_id = 1')
->getQuery()
->execute();

foreach ($rows as $row) {
print_r($row->settings->id . ' : ' . $row->char_value);
}

不要忘记将数据库列作为字段添加到模型中:

class Settings extends Phalcon\Mvc\Model
{
public $id;

public $name;

...

关于mysql - 如何在 Phalcon 中建立有条件的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24919774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com