众所周知MyISAM引擎不支持事务,但是我只是知道不支持事务,并未测试具体的表现是什么,测试代码如下:
try
{
//开启事务
Db::startTrans();
//(1).id为1的数据name字段修改为gao
$isUpdate1 = Db::table('member')->where(['id' => 1])->update([
'name' => 'gao1'
]);
if (!$isUpdate1)
{
throw new Exception('更新第1条数据失败,事务已经回滚.');
}
//(2).id为2的数据name字段修改为chen
$isUpdate2 = Db::table('member')->where(['id' => 2])->update([
'name' => 'chen'
]);
if (!$isUpdate2)
{
throw new Exception('更新第2条数据失败,事务已经回滚.');
}
// 提交事务
Db::commit();
}
catch (Exception $exception)
{
//事务回滚
Db::rollback();
echo $exception->getMessage() . PHP_EOL;
}通过测试发现MyISAM直接忽视开启事务,提交事务,回滚事务,上面的代码相当于你没有写开启事务,提交事务,事务回滚的效果一样,只要有数据库操作一律直接执行。完全等同于下面的代码:
try
{
//(1).id为1的数据name字段修改为gao
$isUpdate1 = Db::table('member')->where(['id' => 1])->update([
'name' => 'gao1'
]);
if (!$isUpdate1)
{
throw new Exception('更新第1条数据失败');
}
//(2).id为2的数据name字段修改为chen
$isUpdate2 = Db::table('member')->where(['id' => 2])->update([
'name' => 'chen'
]);
if (!$isUpdate2)
{
throw new Exception('更新第2条数据失败');
}
}
catch (Exception $exception)
{
echo $exception->getMessage() . PHP_EOL;
} 这里给出的是Demo,事实上正式的网站对HTTP请求头要求完整性非常严格,建议完善请求头. 1.先看验证文件:<?php if($_COOKIE['username']=='a...
md5/sha1+salt方式是目前各大cms常用的加密方式,虽然salt安全,但是各大md5网站也在研究这个方向,那么我们应该选择password_hash动态hash来助力,一种密码有多种hash结果.看代码模拟登陆.<?php //01.注册 $user ='zhang...
posix_ttyname - 获取当前终端设备名称。<?php var_dump( posix_ttyname(STDOUT) );我们启动一个终端,执行上面的代码输出:/dev/tty1我们再启动一个终端,执行上面的代码输...
概念请参考w3school文章: redis watch ,redis exec (看完基本秒懂)(1)基本事务://连接本地的 Redis 服务 $redis = new Redis(); $redis->con...
【一】.基本用法首先看看官方对send方法的解释:Sets the return value of the yield expression and resumes the generato...