示例#1
0
 /**
  * 执行一个SQL语句
  *
  * @param string $sql 执行的SQL语句
  *
  * @return MySQLRecord | false
  */
 function query($sql)
 {
     $res = false;
     for ($i = 0; $i < 2; $i++) {
         $res = Swoole\Client\CLMySQL::query($sql, $this->conn);
         if ($res === false) {
             if (Swoole\Client\CLMySQL::get_last_errno($this->conn) == 2006 or Swoole\Client\CLMySQL::get_last_errno($this->conn) == 2013) {
                 $r = $this->checkConnection();
                 if ($r === true) {
                     continue;
                 }
             }
             \Swoole\Error::info(__CLASS__ . " SQL Error", $this->errorMessage($sql));
             return false;
         }
         break;
     }
     if (!$res) {
         Swoole\Error::info(__CLASS__ . " SQL Error", $this->errorMessage($sql));
         return false;
     }
     if (is_bool($res)) {
         return $res;
     }
     return new CLMySQLRecord($res);
 }
示例#2
0
 /**
  * 执行一个SQL语句
  * @param string $sql 执行的SQL语句
  * @return \PDOStatement
  */
 public final function query($sql)
 {
     if ($this->debug) {
         echo "{$sql}<br />\n<hr />";
     }
     $res = parent::query($sql) or \Swoole\Error::info("SQL Error", implode(", ", $this->errorInfo()) . "<hr />{$sql}");
     return $res;
 }
示例#3
0
 /**
  * 执行一个SQL语句
  * @param $sql 执行的SQL语句
  */
 function query($sql)
 {
     \mysql_real_escape_string($sql, $this->conn);
     $res = \mysql_query($sql, $this->conn);
     if (!$res) {
         echo Swoole\Error::info("SQL Error", \mysql_error($this->conn) . "<hr />{$sql}");
     }
     return new MySQLRecord($res);
 }
 function __construct($host, $port, $ssl = false)
 {
     $flag = $ssl ? SWOOLE_SOCK_TCP | SWOOLE_SSL : SWOOLE_SOCK_TCP;
     $this->sw = new \swoole_server($host, $port, self::$sw_mode, $flag);
     $this->host = $host;
     $this->port = $port;
     Swoole\Error::$stop = false;
     Swoole\JS::$return = true;
     $this->swooleSetting = array('backlog' => 128);
 }
示例#5
0
 private function __construct()
 {
     if (empty($this->app_path)) {
         if (defined('WEBPATH')) {
             $this->app_path = WEBPATH . '/application';
         } else {
             \Swoole\Error::info("core error", __CLASS__ . ": Swoole::\$app_path and WEBPATH empty.");
         }
     }
     define('APPSPATH', $this->app_path);
     $this->config = new \ImReworks\Config();
     $this->config->setPath(APPSPATH . '/configs');
 }
示例#6
0
 function detail()
 {
     $this->session->start();
     if (empty($_GET['aid'])) {
         $this->http->status(404);
         return "缺少AID参数";
     }
     $_user = createModel('UserInfo');
     $_reply = createModel('AskReply');
     $aid = (int) $_GET['aid'];
     $ask = createModel('AskSubject')->get($aid);
     if (!$ask->exist()) {
         $this->http->status(404);
         return Swoole\Error::info("Page not found", "");
     }
     $ask->lcount++;
     $ask->save();
     $timeout['day'] = intval(($ask['expire'] - time()) / 86400);
     $timeout['hour'] = intval(($ask['expire'] - time() - $timeout['day'] * 86400) / 3600);
     $user = $_user->get($ask['uid'])->get();
     $content = model('AskContent')->get($aid)->get();
     $gets['aid'] = $aid;
     $gets['select'] = $_reply->table . '.id as id,uid,sex,best,content,nickname,avatar,addtime';
     $gets['order'] = 'best desc,' . $_reply->table . '.id asc';
     $gets['leftjoin'] = array($_user->table, $_user->table . '.id=' . $_reply->table . '.uid');
     $gets['pagesize'] = 10;
     $gets['page'] = empty($_GET['page']) ? 1 : (int) $_GET['page'];
     $replys = $_reply->gets($gets, $pager);
     $if_vote = true;
     if ($this->user->isLogin()) {
         $vote = $this->swoole->db->query("select count(*) as c from ask_vote where aid={$aid} and uid={$_SESSION['user_id']} limit 1")->fetch();
         if ($vote['c'] > 0) {
             $if_vote = false;
         }
     }
     $this->swoole->tpl->assign('if_vote', $if_vote);
     $this->swoole->tpl->assign('if_vote', $if_vote);
     $this->swoole->tpl->assign('expire', $timeout);
     $this->swoole->tpl->ref('user', $user);
     $this->swoole->tpl->ref('ask', $ask->get());
     $this->swoole->tpl->ref('content', $content);
     $this->swoole->tpl->ref('replys', $replys);
     if ($pager->totalpage > 1) {
         $this->swoole->tpl->ref('pager', $pager->render());
     }
     $this->swoole->tpl->display();
 }
示例#7
0
 /**
  * 执行一个SQL语句
  * @param $sql 执行的SQL语句
  */
 function query($sql)
 {
     for ($i = 0; $i < 2; $i++) {
         $result = parent::query($sql);
         if ($result === false) {
             if ($this->errno == 2013 or $this->errno == 2006) {
                 $r = $this->checkConnection();
                 if ($r === true) {
                     continue;
                 }
             }
             echo \Swoole\Error::info("SQL Error", $this->error . "<hr />{$sql}");
             return false;
         }
         break;
     }
     if ($result === false) {
         echo \Swoole\Error::info("SQL Error", $this->error . "<hr />{$sql}");
         return false;
     }
     return new MySQLiRecord($result);
 }
示例#8
0
文件: MySQL.php 项目: lughong/test
 /**
  * 执行一个SQL语句
  *
  * @param string $sql 执行的SQL语句
  *
  * @return MySQLRecord | false
  */
 function query($sql)
 {
     $res = false;
     for ($i = 0; $i < 2; $i++) {
         $res = mysql_query($sql, $this->conn);
         if ($res === false) {
             if (mysql_errno($this->conn) == 2006 or mysql_errno($this->conn) == 2013) {
                 $r = $this->checkConnection();
                 if ($r === true) {
                     continue;
                 }
             }
             \Swoole\Error::info(__CLASS__ . " SQL Error", $this->errorMessage($sql));
             return false;
         }
         break;
     }
     if (!$res) {
         Swoole\Error::info(__CLASS__ . " SQL Error", $this->errorMessage($sql));
         return false;
     }
     return new MySQLRecord($res);
 }
示例#9
0
 /**
  * 执行一个SQL语句
  * @param string $sql 执行的SQL语句
  * @return MySQLRecord | false
  */
 function query($sql)
 {
     mysql_real_escape_string($sql, $this->conn);
     $res = false;
     for ($i = 0; $i < 2; $i++) {
         $res = mysql_query($sql, $this->conn);
         if ($res === false) {
             if (mysql_errno($this->conn) == 2006 or mysql_errno($this->conn) == 2013) {
                 $r = $this->checkConnection();
                 if ($r === true) {
                     continue;
                 }
             }
             echo \Swoole\Error::info("SQL Error", mysql_error($this->conn) . "<hr />{$sql}");
             return false;
         }
         break;
     }
     if (!$res) {
         echo Swoole\Error::info("SQL Error", mysql_error($this->conn) . "<hr />{$sql}");
         return false;
     }
     return new MySQLRecord($res);
 }
示例#10
0
文件: Swoole.php 项目: abc1225/test2
 /**
  * 设置应用程序路径
  * @param $dir
  */
 static function setAppPath($dir)
 {
     if (is_dir($dir)) {
         self::$app_path = $dir;
     } else {
         \Swoole\Error::info("fatal error", "app_path[{$dir}] is not exists.");
     }
 }
示例#11
0
 function __construct($config = array())
 {
     define('SWOOLE_SERVER', true);
     Swoole\Error::$echo_html = true;
 }
示例#12
0
 /**
  * 执行一个SQL语句
  *
  * @param string $sql 执行的SQL语句
  *
  * @return MySQLiRecord | false
  */
 function query($sql)
 {
     $result = false;
     for ($i = 0; $i < 2; $i++) {
         $result = parent::query($sql);
         if ($result === false) {
             if ($this->errno == 2013 or $this->errno == 2006) {
                 $r = $this->checkConnection();
                 if ($r === true) {
                     continue;
                 }
             } else {
                 if ($this->display_error) {
                     trigger_error(__CLASS__ . " SQL Error: " . $this->errorMessage($sql), E_USER_WARNING);
                     echo Swoole\Error::info("SQL Error", $this->errorMessage($sql));
                 }
                 return false;
             }
         }
         break;
     }
     if (!$result) {
         echo \Swoole\Error::info("SQL Error", $this->errorMessage($sql));
         return false;
     }
     return new MySQLiRecord($result);
 }
示例#13
0
<?php

define('DEBUG', 'on');
define('WEBPATH', __DIR__);
require __DIR__ . '/../vendor/autoload.php';
Swoole\Loader::vendor_init();
\Swoole\Error::dbd();
$sql = "select distinct module_id,interface_id,client_ip from logs";
$res = Swoole::$php->db->query($sql)->fetchall();
$tmp = array();
foreach ($res as $val) {
    $tmp[$val['module_id'] . "_" . $val['interface_id']][$val['client_ip']] = $val['client_ip'];
}
//debug(Swoole::$php->redis);
foreach ($tmp as $m_f_id => $client_ips) {
    foreach ($client_ips as $id) {
        $res = Swoole::$php->redis->sAdd($m_f_id, $id);
        echo $m_f_id . '--' . $id;
        var_dump($res);
        echo "\n";
    }
}
示例#14
0
 function run($array)
 {
     \Swoole\Error::$echo_html = true;
     $this->server->run($array);
 }
示例#15
0
 /**
  * 发生了http错误
  * @param                 $code
  * @param Swoole\Http\Response $response
  * @param string          $content
  */
 function httpError($code, Swoole\Http\Response $response, $content = '')
 {
     $response->send_http_status($code);
     $response->head['Content-Type'] = 'text/html';
     $response->body = Swoole\Error::info(Swoole\Http\Response::$HTTP_HEADERS[$code], "<p>{$content}</p><hr><address>" . self::SOFTWARE . " at {$this->server->host} Port {$this->server->port}</address>");
 }
示例#16
0
 /**
  * 错误显示
  * @param $error
  */
 private function errorResponse($error)
 {
     $errorMsg = "{$error['message']} ({$error['file']}:{$error['line']})";
     $message = Swoole\Error::info(self::SOFTWARE . " Application Error", $errorMsg);
     if (empty($this->currentResponse)) {
         $this->currentResponse = new Swoole\Response();
     }
     $this->currentResponse->setHttpStatus(500);
     $this->currentResponse->body = $message;
     $this->currentResponse->body = defined('DEBUG') && DEBUG == 'on' ? $message : '';
     $this->response($this->currentRequest, $this->currentResponse);
 }
示例#17
0
 /**
  * 执行一个参数化SQL语句
  * @param string $sql 执行的SQL语句
  * @param  mixed $_     [optional]
  * @return int          last insert id
  */
 public final function execute($sql, $_)
 {
     $params = func_get_args();
     if ($this->debug) {
         var_dump($params);
     }
     array_shift($params);
     $stm = $this->prepare($sql);
     if ($stm->execute($params)) {
         return $this->lastInsertId();
     } else {
         \Swoole\Error::info("SQL Error", implode(", ", $this->errorInfo()) . "<hr />{$sql}");
         return false;
     }
 }
示例#18
0
 /**
  * 获取属性
  * @param $property
  *
  * @return null
  */
 function __get($property)
 {
     if (isset($this->_data[$property])) {
         return $this->_data[$property];
     } else {
         Error::pecho("Record object no property: {$property}");
         return null;
     }
 }
示例#19
0
 /**
  * 执行一个SQL语句
  *
  * @param string $sql 执行的SQL语句
  *
  * @return MySQLiRecord | false
  */
 function query($sql)
 {
     $result = false;
     for ($i = 0; $i < 2; $i++) {
         $result = parent::query($sql);
         if ($result === false) {
             if ($this->errno == 2013 or $this->errno == 2006) {
                 $r = $this->checkConnection();
                 if ($r === true) {
                     continue;
                 }
             } else {
                 Swoole\Error::info(__CLASS__ . " SQL Error", $this->errorMessage($sql));
                 return false;
             }
         }
         break;
     }
     if (!$result) {
         Swoole\Error::info(__CLASS__ . " SQL Error", $this->errorMessage($sql));
         return false;
     }
     return new MySQLiRecord($result);
 }
示例#20
0
 function __construct($host, $port, $ssl = false)
 {
     $flag = $ssl ? SWOOLE_SOCK_TCP | SWOOLE_SSL : SWOOLE_SOCK_TCP;
     if (!empty(self::$options['base'])) {
         self::$swooleMode = SWOOLE_BASE;
     } elseif (extension_loaded('swoole')) {
         self::$swooleMode = SWOOLE_PROCESS;
     }
     $this->sw = new \swoole_server($host, $port, self::$swooleMode, $flag);
     $this->host = $host;
     $this->port = $port;
     Swoole\Error::$stop = false;
     Swoole\JS::$return = true;
     $this->runtimeSetting = array('backlog' => 128);
 }
示例#21
0
 /**
  * 捕获错误
  */
 function onError()
 {
     $error = error_get_last();
     if (!isset($error['type'])) {
         return;
     }
     switch ($error['type']) {
         case E_ERROR:
         case E_PARSE:
         case E_DEPRECATED:
         case E_CORE_ERROR:
         case E_COMPILE_ERROR:
             break;
         default:
             return;
     }
     $errorMsg = "{$error['message']} ({$error['file']}:{$error['line']})";
     $message = Swoole\Error::info(self::SOFTWARE . " Application Error", $errorMsg);
     if (empty($this->currentResponse)) {
         $this->currentResponse = new Swoole\Response();
     }
     $this->currentResponse->setHttpStatus(500);
     $this->currentResponse->body = $message;
     $this->response($this->currentRequest, $this->currentResponse);
 }
示例#22
0
 /**
  * 异步SQL
  * @param $sql
  * @return bool|\mysqli_result
  */
 function queryAsync($sql)
 {
     $result = $this->tryReconnect(array('parent', 'query'), array($sql, MYSQLI_ASYNC));
     if (!$result) {
         Swoole\Error::info(__CLASS__ . " SQL Error", $this->errorMessage($sql));
         return false;
     }
     return $result;
 }
示例#23
0
 /**
  * 设置应用程序路径
  * @param $dir
  */
 static function setControllerPath($dir)
 {
     if (is_dir($dir)) {
         self::$controller_path = $dir;
     } else {
         \Swoole\Error::info("fatal error", "controller_path[{$dir}] is not exists.");
     }
 }