$m
=D(
'YourModel'
);
$m2
=D(
'YouModel2'
);
$m
->startTrans();
$result
=
$m
->where(
'删除条件'
)->
delete
();
$result2
=m2->where(
'删除条件'
)->
delete
();
if
(
$result
&&
$result2
){
$m
->commit();
}
else
{
$m
->rollback();
}
$servername
=
"localhost"
;
$username
=
"root"
;
$password
=
"admin"
;
$dbname
=
"test"
;
try
{
$conn
=
new
PDO(
"mysql:host=$servername;dbname=$dbname"
,
$username
,
$password
);
$conn
->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$conn
->beginTransaction();
$conn
->
exec
(
"INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('YE','XIAMING','yexianming@163.com')"
);
$conn
->
exec
(
"INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('YE','CONG','yecong@163.com')"
);
$conn
->
exec
(
"INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('FANG','MENG','fangmeng@168.com')"
);
$conn
->commit();
echo
"New records created successfully!"
;
}
catch
(PDOException
$e
){
$conn
->rollBack();
echo
$sql
.
"<br>"
.
$e
->getMessage();
}
$conn
=NULL;