PHP code example of alan / yii2-orm-dcache
1. Go to this page and download the library: Download alan/yii2-orm-dcache library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alan / yii2-orm-dcache example snippets
//测试环境配置
'dcache_data_center' => [
'url' => 'http://xxx.xxx.xxx.xxx:xxxx',
'key' => 'xxxxxxxx',
]
//测试和正式环境只要表结构一致就只需要添加一处即可
'db_tars_order' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=host;port=port;dbname=db_name',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'enableSchemaCache' => true,
'schemaCacheDuration' => 86400, // time in seconds
],
'db_tars_relationship' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=host;port=prot;dbname=dbname',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'enableSchemaCache' => true,
'schemaCacheDuration' => 86400, // time in seconds
],
/** 查询一条 **/
Invoice::find()->where(['order_sn' =>'xxxxx'])->asArray(false)->one()
/** 查询多条 **/
Invoice::find()->where(['order_sn' =>'xxxxx'])->asArray(false)->all()
/** 取出数组 **/
Invoice::find()->where(['order_sn' =>'xxxxx'])->asArray(false)->asArray()->all()
public function actionUpdate($orderSn){
/** @var Order $order */
$order = Order::find()->where(['order_sn' => $orderSn])->asArray(false)->one();
if (empty($order)){
die("查询失败");
}
print_r($order->toArray());
$order->b_user_id = "1234";
$saveRsp = $order->save();
if (!$saveRsp){
print_r($order->getErrors());
} else {
$order = Order::find()->where(['order_sn' => $orderSn])->asArray(true)->one();
print_r($order);
}
}
public function actionDelete($orderSn){
/** @var Order $order */
$order = Order::find()->where(['order_sn' => $orderSn])->asArray(false)->one();
if (empty($order)){
die("查询失败");
}
$order->delete();
$order = Order::find()->where(['order_sn' => $orderSn])->asArray(true)->one();
print_r($order);
}