データベースにトランザクションをすべて保存するアプリケーションがあります。コントローラのコードは次のようになります:Codeigniterモデルがデータベースに保存されていません
$info = array(
'student_id' => $this->user['id'],
'transaction_id' => $ref,
'value' => $amount,
'final_value' => $final_value,
'payment_status' => '0',
'date' => date('Y-m-d'),
);
$this->load->model('student_model');
if($this->student_model->insertPurchaseForStudent($info)){
// Some other code here
}
そして、これは私のモデル(「student_model」)です:
public function insertPurchaseForStudent($info){
if($this->db->insert('compra', $this->db->escape($info))){
return true;
}else{
return false;
}
}
一部のトランザクションがデータベースに保存されているので、私は巨大な頭痛を抱えているし、他の人がしていますない。私はそれが私のデータベースサーバ上の不安定性のいくつかの種類かもしれないと思ったので、私は複数回試してみて、それが保存できない場合は、エラー・メッセージをログに記録する、ループためを追加しました:
$i = 1;
for ($i == 1; $i <= 5; $i++) {
if($this->student_model->insertPurchaseForStudent($info)){
// to leave the loop
$i = 7;
// Some other code here
}else{
sleep(3);
switch($i){
case 2 :
log_message('error', 'Second attempt to add transaction');
break;
case 3 :
log_message('error', 'Third attempt to add transaction');
break;
case 4 :
log_message('error', 'Fourth attempt to add transaction');
break;
case 5 :
log_message('error', 'Fifth attempt to add transaction');
break;
case 6 :
log_message('error', 'Sixth attempt, giving up');
break;
}
}
}
問題は、トランザクションを保存しないと、エラーログにメッセージが表示されません。
私は本当に何が原因であるか、私が書いたこのコードではどこがずれているのかというアイデアに感謝します。
乾杯。
「$ info」とは何ですか? – quantme
ごめんなさい@quantme、$ infoはトランザクション情報の配列です。私は私の質問を更新しました。ありがとう! – grpaiva
'$ this-> user ['id']'は、前回の/現在のデータベース操作やセッションからのものですか? – quantme