使用 phalcon,我有两个数据库,如何使用 modelsManager 在 $builder 之前 select 一个数据库?
Using phalcon, I have two databases, How can I select a database before $builder with modelsManager?
在这个$builder之前,我想设置一个数据库,怎么办?提前致谢!
$builder = $this->modelsManager->createBuilder()
->columns($cols)
->distinct(true)
->from($ZUC)
->leftJoin($ZU, "$ZU.user_id = $ZUC.user_id")
->leftJoin($ZSC, "$ZUC.subclass_id = $ZSC.subclass_id")
->leftJoin($ZC, "$ZC.class_id = $ZSC.class_id")
->leftJoin($ZCH, "$ZCH.order_no = $ZUC.order_no")
->where($conStr, $conArr)
->orderBy($order)
在 di 中更改数据库服务或在模型中使用 setReadConnectionService 方法(尽管不确定最后一个)。
可以使用setSchema()方法来定义,这里是参考;
Link
分享给你。点赞
$zx_user_class = new ZxUserClass(); //your primary table
$zx_user_class->setConnectionService('dbWrite'); // select databse
$modelsManager = $zx_user_class->getModelsManager();
$builder = $modelsManager->createBuilder()
->columns($cols)
->distinct(true)
->from($ZUC)
->leftJoin($ZU, "$ZU.user_id = $ZUC.user_id")
->leftJoin($ZSC, "$ZUC.subclass_id = $ZSC.subclass_id")
->leftJoin($ZC, "$ZC.class_id = $ZSC.class_id")
->leftJoin($ZCH, "$ZCH.order_no = $ZUC.order_no")
->where($conStr, $conArr)
->orderBy($order)
在这个$builder之前,我想设置一个数据库,怎么办?提前致谢!
$builder = $this->modelsManager->createBuilder()
->columns($cols)
->distinct(true)
->from($ZUC)
->leftJoin($ZU, "$ZU.user_id = $ZUC.user_id")
->leftJoin($ZSC, "$ZUC.subclass_id = $ZSC.subclass_id")
->leftJoin($ZC, "$ZC.class_id = $ZSC.class_id")
->leftJoin($ZCH, "$ZCH.order_no = $ZUC.order_no")
->where($conStr, $conArr)
->orderBy($order)
在 di 中更改数据库服务或在模型中使用 setReadConnectionService 方法(尽管不确定最后一个)。
可以使用setSchema()方法来定义,这里是参考; Link
分享给你。点赞
$zx_user_class = new ZxUserClass(); //your primary table
$zx_user_class->setConnectionService('dbWrite'); // select databse
$modelsManager = $zx_user_class->getModelsManager();
$builder = $modelsManager->createBuilder()
->columns($cols)
->distinct(true)
->from($ZUC)
->leftJoin($ZU, "$ZU.user_id = $ZUC.user_id")
->leftJoin($ZSC, "$ZUC.subclass_id = $ZSC.subclass_id")
->leftJoin($ZC, "$ZC.class_id = $ZSC.class_id")
->leftJoin($ZCH, "$ZCH.order_no = $ZUC.order_no")
->where($conStr, $conArr)
->orderBy($order)