/** * 初始化数据库配置 * @param string $table * @param boolean $isMaster * @param boolean $isPersistent * @return Base_Db */ public function prepare($table, $isMaster = false, $isPersistent = false) { if (!isset($this->tableConf[$table])) { die($table . ' to database config error'); } $dbKey = $this->tableConf[$table]['db']; $db_count = count($this->dbConf[$dbKey]); $writeConf = array('host' => $this->dbConf[$dbKey][0]['host'], 'user' => $this->dbConf[$dbKey][0]['user'], 'password' => $this->dbConf[$dbKey][0]['password'], 'port' => empty($this->dbConf[$dbKey][0]['port']) ? 3306 : $this->dbConf[$dbKey][0]['port'], 'database' => $this->dbConf[$dbKey][0]['database']); if ($db_count >= 2) { $rand = rand(1, $db_count - 1); $readConf = array('host' => $this->dbConf[$dbKey][$rand]['host'], 'user' => $this->dbConf[$dbKey][$rand]['user'], 'password' => $this->dbConf[$dbKey][$rand]['password'], 'port' => empty($this->dbConf[$dbKey][$rand]['port']) ? 3306 : $this->dbConf[$dbKey][$rand]['port'], 'database' => $this->dbConf[$dbKey][$rand]['database']); } else { $readConf = $writeConf; } $key = md5($writeConf['host'] . ':' . $writeConf['port'] . ';' . $writeConf['user'] . ':' . $writeConf['password']); if (isset($this->oDbArr[$key]) && is_object($this->oDbArr[$key])) { if ($isMaster) { $this->oDbArr[$key]->setIsMaster($isMaster); } } else { require_once "pdo.class.php"; $oDb = new pdodb(); $oDb->setReadConf($readConf); $oDb->setWriteConf($writeConf); $oDb->setIsMaster($isMaster); $isPersistent = $isPersistent || $this->dbConf['isPersistent']; $oDb->setIsPersistent($isPersistent); $this->oDbArr[$key] = $oDb; } return $this->oDbArr[$key]; }
function deletePicture($data) { $results = []; //checks if requests needed are present and not empty $dataNeeded = array("username"); if (checkData($data, $dataNeeded)) { //check if user provided exists $user = getAUser($data["username"]); if ($user["count"] > 0) { //update database $db = new pdodb(); $query = "UPDATE User SET Picture = null WHERE Username = :username;"; $bindings = array(":username" => $data["username"]); $picture = $db->query($query, $bindings); //if update was ok if ($picture["count"] > 0) { //checks if file exists to delete the picture if (file_exists($user["rows"][0]["Picture"])) { unlink($user["rows"][0]["Picture"]); } //return updated user $results = getAUser($data["username"]); $results["meta"]["ok"] = true; } else { //check if database provided any meta data if so problem with executing query if (isset($picture["meta"])) { $results = $picture; } else { $results["meta"]["ok"] = false; } } } else { //check if database provided any meta data if so problem with executing query if (isset($user["meta"])) { $results = $user; } else { $results["meta"] = noUserFound($data["username"]); } } } else { $results["meta"] = dataNotProvided($dataNeeded); } return $results; }
(w.execute_date >= '2011-03-21' or w.issue_date >= '2011-03-21' ) ) ,(w.state = 3 OR w.view_flag = 1), (1=1)) and substr(g2j(execute_date),3,2) >= 83 ".$WClause." order by issue_date DESC ,execute_date DESC, writ_ver DESC "); $count_res = $countsql ->ExecuteStatement(array($HrmsPersonID)); $count_res = $count_res->fetchAll(); $cnt = count($count_res); $totaln = $cnt; if(!isset($_GET['rfsh'])) $s = 0; if (isset($_GET['rfsh'])) $s = $_GET['start']; $mysql = pdodb::getInstance(); $mysql->prepare ("select *, substr(g2j(execute_date),3,2),wt.title as wt_title , wst.title as wst_title ,w.description from hrmstotal.writs w INNER JOIN hrmstotal.staff s on (w.staff_id = s.staff_id) INNER JOIN hrmstotal.writ_types wt on (w.writ_type_id = wt.writ_type_id AND w.person_type = wt.person_type) INNER JOIN hrmstotal.writ_subtypes wst on (w.writ_type_id = wst.writ_type_id and w.writ_subtype_id = wst.writ_subtype_id AND w.person_type = wst.person_type) where s.PersonID= ? and /*if(s.person_type in (2,5) , w.execute_date < '2014-03-21' , (1=1) ) and*/ if( ((s.person_type = 2 or s.person_type = 3 or s.person_type = 5 or s.person_type = 6 ) and ( w.execute_date >= '2011-03-21' or w.issue_date >= '2011-03-21') ) ,( w.state = 3 OR w.view_flag = 1 ), (1=1)) and substr(g2j(execute_date),3,2) >= 83 ".$WClause." order by issue_date DESC ,execute_date DESC, writ_ver DESC limit ".$s.",10
function deletePicture($data) { //checks if requests needed are present and not empty $dataNeeded = array("username", "password", "projectID", "file"); if (checkData($data, $dataNeeded)) { //checks if user provided exists $results = login($data); if ($results["meta"]["ok"] === true) { //error getting goal $results = getProject($data["projectID"]); if ($results["count"] > 0) { //update database $db = new pdodb(); $query = "DELETE FROM PortfolioProjectImage WHERE ProjectID = :projectID AND File = :file;"; $bindings = array(":projectID" => $data["projectID"], ":file" => $data["file"]); $results = $db->query($query, $bindings); //if update was ok if ($results["count"] > 0) { //checks if file exists to delete the picture if (file_exists($data["file"])) { unlink($data["file"]); } $results["meta"]["ok"] = true; $results["rows"]["file"] = $data["file"]; } else { //check if database provided any meta data if so problem with executing query if (!isset($results["meta"])) { $results["meta"]["ok"] = false; } } } } } else { $results["meta"] = dataNotProvided($dataNeeded); } return $results; }