Ejemplo n.º 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;
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 4
0
 /**
  * 执行SQL语句并返回结果集中一行的某一列
  * @param string $sql
  * @param int $column
  * @return mixed
  * @throws Exception
  */
 public function fetchColumn($sql, $column = 0)
 {
     util_log::appLog()->info("SQL: {$sql}");
     try {
         $statement = $this->query($sql);
     } catch (Exception $e) {
         throw $e;
     }
     return $statement->fetchColumn($column);
     //如果没有记录,返回false
 }