errorCode() != 0)) { /* 识别错误 */ $error = PDO_ErrorInfo(); return $error[2]; } else { #没错误 return ""; } } class Sent_DB { public $dbh_sent; public $dbh_his; private $errorMsg=""; public function __construct() { $this->dbh_sent = new PDO(_FILE_DB_SENTENCE_, "", "",array(PDO::ATTR_PERSISTENT=>true)); $this->dbh_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $this->dbh_his = new PDO(_FILE_DB_USER_SENTENCE_HISTORAY_, "", "",array(PDO::ATTR_PERSISTENT=>true)); $this->dbh_his->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); } public function getError(){ return $errorMsg; } public function update($arrData){ /* 修改现有数据 */ if (count($arrData) > 0) { //add_edit_event(_SENT_EDIT_, "{$oldList[0]["book"]}-{$oldList[0]["paragraph"]}-{$oldList[0]["begin"]}-{$oldList[0]["end"]}@{$oldList[0]["channal"]}"); $this->dbh_sent->beginTransaction(); $query = "UPDATE sentence SET text = ? , strlen = ? , editor=?, modify_time= ? where id= ? "; $sth = $this->dbh_sent->prepare($query); foreach ($arrData as $data) { $sth->execute(array($data["text"],mb_strlen($data["text"],"UTF-8"),$data["editor"],mTime(),$data["id"])); } $this->dbh_sent->commit(); if (!$sth || ($sth && $sth->errorCode() != 0)) { /* 识别错误且回滚更改 */ $this->dbh_sent->rollBack(); $error = $this->dbh_sent->errorInfo(); $this->errorMsg = $error[2]; return false; } else { #没错误 添加log $this->errorMsg = ""; return true; } } else{ $this->errorMsg = ""; return true; } } public function insert($arrData){ /* 插入新数据 */ //查询channel语言 if (count($arrData) > 0) { //add_edit_event(_SENT_NEW_, "{$newList[0]["book"]}-{$newList[0]["paragraph"]}-{$newList[0]["begin"]}-{$newList[0]["end"]}@{$newList[0]["channal"]}"); $this->dbh_sent->beginTransaction(); $query = "INSERT INTO sentence (id, parent, book, paragraph, begin, end, channal, tag, author, editor, text, language, ver, status, strlen, modify_time, receive_time, create_time ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; $sth = $this->dbh_sent->prepare($query); $channel_info = new Channal(); foreach ($arrData as $data) { if($data["id"]==""){ $data["id"] = UUID::v4(); } $queryChannel = $channel_info->getChannal($data["channal"]); if ($queryChannel == false) { $lang = $data["language"]; $status = 10; } else { $lang = $queryChannel["lang"]; $status = $queryChannel["status"]; } $sth->execute(array($data["id"], isset($data["parent"]) ? $data["parent"] : "", $data["book"], $data["paragraph"], $data["begin"], $data["end"], $data["channal"], isset($data["tag"]) ? $data["tag"] : "", $data["author"], $data["editor"], $data["text"], $lang, 1, $status, mb_strlen($data["text"], "UTF-8"), mTime(), mTime(), mTime(), )); } $this->dbh_sent->commit(); if (!$sth || ($sth && $sth->errorCode() != 0)) { /* 识别错误且回滚更改 */ $this->dbh_sent->rollBack(); $error = $this->dbh_sent->errorInfo(); $this->errorMsg = $error[2]; return false; } else { $this->errorMsg = ""; return true; } } else{ $this->errorMsg = ""; return true; } } public function send_pr($arrData){ if (count($arrData) ==0) { $this->errorMsg = ""; return true; } $this->dbh_sent->beginTransaction(); $query = "INSERT INTO sent_pr (id, book, paragraph, begin, end, channel, tag, author, editor, text, language, status, strlen, modify_time, receive_time, create_time ) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"; $stmt = $this->dbh_sent->prepare($query); foreach ($arrData as $data) { # 初始状态 1 未处理 $stmt->execute(array( $data["book"], $data["para"], $data["begin"], $data["end"], $data["channal"], "", "[]", $data["editor"], $data["text"], $data["language"], 1, mb_strlen($data["text"], "UTF-8"), mTime(), mTime(), mTime(), )); } $this->dbh_sent->commit(); if (!$stmt || ($stmt && $stmt->errorCode() != 0)) { # 识别错误 $this->dbh_sent->rollBack(); $error = $this->dbh_sent->errorInfo(); $this->errorMsg = $error[2]; return false; } else { # 没错误 $this->errorMsg = ""; return true; } } public function historay($arrData) { if (count($arrData) ==0) { $this->errorMsg = ""; return true; } $this->dbh_his->beginTransaction(); # 更新historay $query = "INSERT INTO sent_historay (sent_id, user_id, text, date, landmark) VALUES (? , ? , ? , ? , ? )"; $stmt = $this->dbh_his->prepare($query); foreach ($arrData as $data) { $stmt->execute(array($data["id"], $data["editor"], $data["text"], mTime(), $data["landmark"])); } if (!$stmt || ($stmt && $stmt->errorCode() != 0)) { /* 识别错误 */ $this->dbh_sent->rollBack(); $error = $this->dbh_sent->errorInfo(); $this->errorMsg = $error[2]; return false; } else { #没错误 $this->errorMsg = ""; return true; } } }