Beispiel #1
0
 function query($sql, $is_read = true)
 {
     $result = mysql_query($sql, self::$conn[$this->i]);
     $log = config('log', 'mysql');
     $log['is_record_sql'] and logger::sql($sql, $is_read);
     if ($result) {
         return $result;
     }
     $info = $sql . ' {' . mysql_error() . '}';
     $log['is_record_exception'] and logger::exception('mysql', $info);
     throw new Exception($info, 104);
 }
Beispiel #2
0
 function __construct($message, $code, $error = 0)
 {
     logger::exception('server', $code . ' : ' . $message);
     $this->error = $error;
     parent::__construct($message, $code);
 }
Beispiel #3
0
 static function socket($url, $data)
 {
     //解析url
     if (!is_array($url)) {
         $url = parse_url($url);
     }
     if (!isset($url["port"])) {
         $url['port'] = 80;
     }
     //打开socket
     $fp = fsockopen($url['host'], $url['port'], $error_no, $error_info, 30);
     if (!$fp) {
         $info = 'error:(' . $error_no . ')' . $error_info;
         logger::exception('socket', $info);
         throw new Exception($info, 107);
     }
     //组装发送数据
     if (is_array($data)) {
         $data = http_build_query($data);
     }
     $data = trim($data);
     //构造头部信息
     $head = 'POST ' . $url['path'] . " HTTP/1.0\r\n";
     $head .= 'Host: ' . $url['host'] . "\r\n";
     $head .= 'Referer: http://' . $url['host'] . $url['path'] . "\r\n";
     $head .= "Content-type: application/x-www-form-urlencoded\r\n";
     $head .= 'Content-Length: ' . strlen($data) . "\r\n\r\n";
     $head .= $data;
     //接收并返回结果
     fputs($fp, $head);
     $info = '';
     while (!feof($fp)) {
         $info = fgets($fp);
     }
     return json_decode($info, true);
 }
Beispiel #4
0
 static function send($to, $title, $content, $cc = '', $type = 'HTML')
 {
     $mail = self::get_instance();
     $from = config('from', 'mail');
     $mail->send_mails($to, $title, $content, $type, $from, $cc);
     if (self::$exception) {
         logger::exception('mail', implode(PHP_EOL, self::$exception));
     }
 }
Beispiel #5
0
 static function bootstrap($controller, $method)
 {
     try {
         if ($controller && $method) {
             define('CURRENT_ACTION', substr($controller . ':' . $method, 2));
             if (property_exists($controller, 'static_class')) {
                 if (method_exists($controller, '__before')) {
                     call_user_func($controller . '::__before');
                 }
                 call_user_func(array($controller, $method), explode('/', URL_REQUEST));
                 if (method_exists($controller, '__after')) {
                     call_user_func($controller, '::__after');
                 }
             } else {
                 $object = new $controller();
                 if (method_exists($controller, '__before')) {
                     $object->__before();
                 }
                 call_user_func_array(array($object, $method), array(explode('/', URL_REQUEST)));
                 if (method_exists($controller, '__after')) {
                     $object->__after();
                 }
             }
         } else {
             throw new Exception('absent controller or method', 101);
         }
     } catch (Exception $e) {
         logger::exception('exception', $e->getCode() . ' : ' . $e->getMessage());
         if (preg_match('/^(similar|product)$/', ENVIRONMENT)) {
             if (http::is_ajax()) {
                 http::json(array('error' => 4, 'message' => $e->getMessage(), 'data' => null));
             } else {
                 http::abort($e->getMessage(), '', 10);
             }
         }
         debug::exception($e);
     }
 }