我写了一些代码来检查数据库表名称是否为hms_history,如果type = commision,则将向hms_history中添加另一个数据,但将amount_balance更改为-amount_balance,然后向表hms_deposit中添加另一个数据,我尝试编写代码,但是当我检查时它显示仅连接susseccesfull,但数据库中没有任何变化,这就是我的代码
<?php
$servername = "localhost";
$username = "xxxx";
$password = "xxxx";
function setChecked($conn,$params) {
$s = $conn->prepare("UPDATE `hm2_history`
SET ref_id=-1
WHERE id=:id
");
$s->execute($params);
}
try {
$conn = new PDO("mysql:host=$servername;dbname=xxxx", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$stmt = $conn->prepare("SELECT * FROM hm2_history
WHERE id NOT IN(SELECT ref_id FROM hm2_history WHERE ref_id > 0) AND
ref_id=0 AND commission=0");
//deposits
$s = $conn->prepare("INSERT INTO `hm2_deposits`
SET `user_id`=:user_id,
`type_id`=:type_id,
`deposit_date`=:deposit_date,
`last_pay_date`=:last_pay_date,
`status`=:status,
`q_pays`=:q_pays,
`amount`=:amount,
`actual_amount`=:actual_amount,
`ec`=:ec,
`compound`=:compound,
`dde`=:dde,
`unit_amount`=:unit_amount,
`bonus_flag`=:bonus_flag,
`init_amount`=:init_amount,
`ref_id`=:ref_id
");
$v['type_id']= 9;
unset($v['id']);
$lastDepositId = $conn->lastInsertId();
$date = date('Y-m-d H:i:s');
$s->execute($v);
//history1
$s = $conn->prepare("INSERT INTO `hm2_history`
SET `user_id`=:user_id,
`amount`=:amount,
`type`=:type,
`description`=:description,
`actual_amount`=:actual_amount,
`date`=:date,
`ec`=:ec,
`deposit_id`=:deposit_id,
`rate`=:rate
");
$x = array(
'user_id'=>$v['user_id'],
'type'=>'bonus',
'amount'=>$v['amount'],
'description'=>'Bonus note',
'actual_amount'=>$v['actual_amount'],
'date'=>$date,
'ec'=>68,
'deposit_id'=>0,
'rate'=>1.0,
);
$s->execute($x);
//history2
$s = $conn->prepare("INSERT INTO `hm2_history`
SET `user_id`=:user_id,
`amount`=:amount,
`type`=:type,
`description`=:description,
`actual_amount`=:actual_amount,
`date`=:date,
`ec`=:ec,
`deposit_id`=:deposit_id,
`rate`=:rate
");
$x = array(
'user_id'=>$v['user_id'],
'type'=>'depoit',
'amount'=> -$v['amount'],
'description'=>'Deposit from plan',
'actual_amount'=> -$v['actual_amount'],
'date'=>$date,
'ec'=>999,
'deposit_id'=>$lastDepositId,
'rate'=>1.0,
);
$s->execute($x);
?>