【发布时间】:2019-06-08 00:43:12
【问题描述】:
我尝试使用 cake2 中的 getlog 函数获取 sql 语句的最后一个查询。我通常会得到的是 sql 查询,但我得到的是这个:
$sample: array(3)
0: array(5)
query: "Commit"
params : array(0)
affected : false
numRows : false
took : false
我试图通过取消设置一些数组数据来匹配输入到数据库中的数据,但它仍然得到如上所述的输出。有谁知道如何从保存功能中获取 sql 查询?提前致谢
代码如下:
public function mod_edit_confirm() {
$data = $this->Session->read('data_product_edit');
$title = 'Product Edit Confirmation';
$button = 'Update';
$link = '/products/edit/'.$data['MstProduct']['id'];
$product_type = $this->MstProductType->findById($data['MstProduct']['product_type_id']);
if(isset($data['MstProduct']['sales_price']) && $data['MstProduct']['sales_price'] != ''){
$data['MstProduct']['sales_price'] = number_format($data['MstProduct']['sales_price']);
}
if(isset($data['MstProduct']['adjustment_of_amount_of_tax_exclusive']) && $data['MstProduct']['adjustment_of_amount_of_tax_exclusive'] != ''){
$data['MstProduct']['adjustment_of_amount_of_tax_exclusive'] = number_format($data['MstProduct']['adjustment_of_amount_of_tax_exclusive']);
}
if(isset($data['MstProduct']['price_of_option_or_goods']) && $data['MstProduct']['price_of_option_or_goods'] != ''){
$data['MstProduct']['price_of_option_or_goods'] = number_format($data['MstProduct']['price_of_option_or_goods']);
}
if(isset($data['MstProduct']['display_price_without_tax']) && $data['MstProduct']['display_price_without_tax'] != ''){
$data['MstProduct']['display_price_without_tax'] = number_format($data['MstProduct']['display_price_without_tax']);
}
if(isset($data['MstProduct']['amount_of_charge_points']) && $data['MstProduct']['amount_of_charge_points'] != ''){
$data['MstProduct']['amount_of_charge_points'] = number_format($data['MstProduct']['amount_of_charge_points']);
}
if(isset($data['MstProduct']['amount_of_bonus_points']) && $data['MstProduct']['amount_of_bonus_points'] != ''){
$data['MstProduct']['amount_of_bonus_points'] = number_format($data['MstProduct']['amount_of_bonus_points']);
}
$category = $this->Category->findById($data['MstProduct']['category_id']);
if ($this->request->is('post')) {
//click register product
if (isset($this->request->data['Save'])) {
$data = $this->Session->read('data_product_edit');
if ($data['MstProduct']['color_1'] != '')
$data['MstProduct']['color_1'] = trim($data['MstProduct']['color_1'],"#");
if ($data['MstProduct']['color_2'] != '')
$data['MstProduct']['color_2'] = trim($data['MstProduct']['color_2'],"#");
unset($data['MstProduct']['end_radio']);
unset($data['MstProduct']['start_radio']);
unset($data['MstProduct']['category1']);
unset($data['MstProduct']['category2']);
unset($data['MstProduct']['category3']);
unset($data['MstProduct']['category4']);
unset($data['MstProduct']['category5']);
unset($data['Confirm']);
$this->MstProduct->id = $data['MstProduct']['id'];
if ($this->MstProduct->save($data)) {
// here is where i get my datalogs
$sample=$this->MstProduct->getDataSource()->getLog(false, false);
$this->Session->delete('data_product_edit');
if ($data['MstProduct']['product_type_id'] == 1) {
$this->MstProduct->saveField('amount_of_charge_points', '');
} else if ($data['MstProduct']['product_type_id'] == 2) {
$this->MstProduct->saveField('treatment_minutes', '');
} else {
$this->MstProduct->saveField('treatment_minutes', '');
$this->MstProduct->saveField('amount_of_charge_points', '');
}
$this->Flash->success(__d('admin', 'Successfully Updated.'));
return $this->redirect('/products/edit/complete');
} else {
$this->Flash->error(__d('admin', 'Updated Faild.'));
return $this->redirect('/products/edit/'.$data['MstProduct']['id']);
}
} else if (isset($this->request->data['Cancel'])) {
$this->Session->delete('data_product_edit');
return $this->redirect('/products');
}
}
$this->set(compact('data', 'product_type', 'title', 'link', 'category', 'button'));
$this->render("mod_add_confirm");
}
【问题讨论】:
标签: php mysql cakephp mysql-workbench cakephp-2.0