Exemple #1
0
 /**
  * 执行写入动作
  *
  * @param  [type] $sql    [description]
  * @param  array $params [description]
  *
  * @return [type]         [description]
  */
 public function execute($sql, array $params = array())
 {
     //重置option属性
     $this->resetOption();
     //准备sql
     $sth = self::$writeLink->prepare($sql);
     //绑定参数
     $id = 1;
     foreach ($params as $value) {
         $name = "hd{$id}";
         ${$name} = $value;
         $sth->bindParam($id++, ${$name}, PDO::PARAM_STR);
     }
     try {
         //执行查询
         $sth->execute();
         //记录查询日志
         if (DEBUG) {
             //记录查询日志
             self::$queryLog[] = $sql;
         }
         //返回受影响行数
         return self::$affectedRow = $sth->rowCount();
     } catch (Exception $e) {
         if (DEBUG) {
             $error = $sth->errorInfo();
             throw new Exception($sql . " ;BindParams:" . var_export($params, true) . implode(';', $error));
         } else {
             return false;
         }
     }
 }