শনিবার, ২৭ আগস্ট, ২০১৬

Insert row or update if it exists(PDO)

$statement1=$db->prepare('select * from tbl_accounting where a_date=?');
$statement1->execute(array($c_date));
$result1=$statement1->fetchColumn();
if($result1>0) //checking existance and update section
{
$statement2=$db->prepare("update tbl_accounting set a_balance=? where a_date=?");
 $statement2->execute(array($todays_balance,$c_date));
}
else{ // insert section
 $statement2=$db->prepare("insert into tbl_accounting(a_balance,a_date) values(?,?) ");
 $statement2->execute(array($todays_balance,$c_date));


}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন