第二个数据库yii2
Second database yii2
我在yii2上有一个网站。我需要连接到远程数据库来获取产品。对于本地数据库,我这样做:
$query = new Query;
$query->select(['product_sku'])
->from('ntc7r_virtuemart_products')
->where(['virtuemart_product_id' => $product_id]);
但是当我尝试通过代码连接到远程数据库时:
$query = Yii::$app->db2->createCommand((new \yii\db\Query)->select(['product_sku'])->from('ntc7r_virtuemart_products'))->where(['virtuemart_product_id' => $product_id])->queryAll()
我报错
Object of class yii\db\Query could not be converted to string
你可以这样做
(new Query())->select(['product_sku'])->from('ntc7r_virtuemart_products')->where(['virtuemart_product_id' => $product_id])->all(Yii::$app->db2);
我在yii2上有一个网站。我需要连接到远程数据库来获取产品。对于本地数据库,我这样做:
$query = new Query;
$query->select(['product_sku'])
->from('ntc7r_virtuemart_products')
->where(['virtuemart_product_id' => $product_id]);
但是当我尝试通过代码连接到远程数据库时:
$query = Yii::$app->db2->createCommand((new \yii\db\Query)->select(['product_sku'])->from('ntc7r_virtuemart_products'))->where(['virtuemart_product_id' => $product_id])->queryAll()
我报错
Object of class yii\db\Query could not be converted to string
你可以这样做
(new Query())->select(['product_sku'])->from('ntc7r_virtuemart_products')->where(['virtuemart_product_id' => $product_id])->all(Yii::$app->db2);