Exemplo n.º 1
0
Arquivo: db.php Projeto: Honvid/HCMS
 /**
  * 执行全局sql
  * @param $sql
  * @param array $bindArray
  * @param null $action
  * @return array|int|mixed|null|string
  */
 public function execute($sql, $bindArray = array(), $action = null)
 {
     $sqlStartTime = getMillisecond();
     $stmt = $this->link->prepare($sql);
     $ok = $stmt->execute($bindArray);
     $res = null;
     switch ($action) {
         case "select":
             $res = $stmt->fetch(\PDO::FETCH_ASSOC);
             break;
         case "selectAll":
             $res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
             break;
         case "update":
         case "delete":
             $res = $stmt->rowCount();
             break;
         case "insert":
             $res = $this->link->lastInsertId();
             break;
         case "count":
             $res = $stmt->rowCount();
             break;
     }
     $this->options = array();
     $sqlEndTime = getMillisecond();
     $showLog = C("SQL_LOG");
     if ($showLog) {
         Log::write(sprintf("SQL COSETIME=【%s】ms,ERRORCODE=【%s】,SQL=【%s】,BIND=【%s】", $sqlEndTime - $sqlStartTime, $ok, $sql, json_encode($bindArray)), Log::SQL);
     }
     if (!$ok) {
         Log::write("SQL ERROR=" . json_encode($stmt->errorInfo()), Log::ERROR);
         throw new Exception(json_encode($stmt->errorInfo()));
     }
     return $res;
 }
Exemplo n.º 2
0
 public function test1()
 {
     Log::write("error01", Log::ERROR);
     echo "ok";
 }