我想打印我执行的存储过程的结果。
这是我尝试过的代码:
public function actionGetdata($tranId) {
$model = new ReceivedGoodsDetail();
// $model = $this->findModel($tranId);
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction();
//set nilai default
$model->ID_Received_Goods = $tranId;
if ($model->validate()) {
$connection = Yii::$app->db;
$command = $connection->createCommand('{call usp_T_Sales_Inventory_Detail#SelectData(:ID_Received_Goods)}');
$ID_Received_Goods = $model->ID_Received_Goods;
$command->bindParam(":ID_Received_Goods", $ID_Received_Goods, PDO::PARAM_STR);
$isSuccess = 0;
if ($command->execute()) {
$transaction->commit();
$isSuccess = 1;
} else {
$transaction->rollBack();
$isSuccess = 0;
}
return [
'data' => $isSuccess
];
} else {
$isSuccess = 0;
return [
'data' => $isSuccess,
'error' => $model->getErrors(),
];
}
}
当我在RESTClient中尝试这个时,结果是
<response>
<data>1</data>
</response>
虽然我希望结果会显示
的结果select *
from T_Received_Goods_Detail
where ID_Received_Goods = 'RG/1608/11'
请帮忙。
答案 0 :(得分:0)
因此,不是返回$isSuccess
的值,而是可以运行您的查询,并在操作成功的情况下返回结果。
在伪代码中:
if ($isSucces) {
$data = [result of query "select * from T_Received_Goods_Detail where ..."];
return [
'data' => $data
];
}
确保$data
是一个普通数组,REST接口将为您输出有效的响应。