示例#1
0
 public function post($post_params, $get_params = array())
 {
     $url = $this->url . "?";
     foreach ($get_params as $key => $value) {
         $url .= "{$key}={$value}&";
     }
     $ch = curl_init($this->_cutTail($url, '&'));
     curl_setopt($ch, CURLOPT_ENCODING, "UTF-8");
     //curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_TIMEOUT, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
     $ret = curl_exec($ch);
     $info = curl_getinfo($ch);
     $errno = curl_errno($ch);
     $error = curl_error($ch);
     if (!$ret) {
         util_log::monitor()->error(array('MONITOR_KEY' => "CURL_FAILED", "url" => $url, "errno" => $errno, "error" => $error));
     }
     curl_close($ch);
     return $ret;
 }
示例#2
0
 /**
  * 构造器
  * @param $dsn
  * @param $username
  * @param $password
  * @param array $options
  * @throws Exception
  */
 public function __construct($dsn = "", $username = "", $password = "", $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'set names utf8'))
 {
     try {
         parent::__construct($dsn, $username, $password, $options);
     } catch (Exception $e) {
         util_log::monitor()->error(array('MONITOR_KEY' => "database_failed", "dsn" => $dsn, "username" => $username, "passward" => $password));
         $url = AppConfig::ERROT_PAGE . $e->getCode();
         header('Location:' . $url);
         throw $e;
     }
 }
示例#3
0
 /**
  * 构造器
  * @param string $dbname 数据库名
  * @throws Exception
  */
 public function __construct($config)
 {
     try {
         $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'set names utf8');
         $dbname = SysConfig::$db_config[$config]['dbname'];
         $host = SysConfig::$db_config[$config]['host'];
         $port = SysConfig::$db_config[$config]['port'];
         $password = SysConfig::$db_config[$config]['password'];
         $username = SysConfig::$db_config[$config]['username'];
         parent::__construct("mysql:dbname={$dbname};host=" . $host . ";port=" . $port, $username, $password, $options);
     } catch (Exception $e) {
         util_log::monitor()->error('ERROR_DB_ORDERS: ' . $e->getMessage());
         throw $e;
     }
 }
示例#4
0
 /**
  * 执行SQL语句并获取结果集中所有行(数组)的数组
  * @param string $sql
  * @return mixed
  * @throws Exception
  */
 public function fetchAll($sql)
 {
     util_log::appLog()->info("SQL: {$sql}");
     try {
         $statement = $this->query($sql);
     } catch (Exception $e) {
         throw $e;
     }
     $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
     //如果没有记录,返回array()
     if ($rows === false) {
         $errorInfo = $this->errorInfo();
         $errorCode = $this->errorCode();
         util_log::monitor()->error(array('MONITOR_KEY' => "database_failed", 'errorCode' => $errorCode, 'errorInfo' => $errorInfo, 'sql' => $sql));
         throw new Exception($errorInfo, $errorCode);
     }
     return $rows;
 }