public function __construct($host, $port, $user, $passwd = '', $dbName = '', $table = '')
 {
     if (empty($port)) {
         $port = 3306;
     }
     if (empty($host) || empty($user)) {
         return;
     }
     $this->dbName = $dbName;
     $this->table = $table;
     $dsn = "mysql:host={$host}:{$port}" . $dbName ? ";dbname={$dbName}" : '';
     $this->db = CommonMysql::getInstance($dsn, $user, $passwd);
 }
 /**
  * 判断登录
  */
 public static function checkLogin()
 {
     if (empty($_SESSION['number'])) {
         header('Location:index.php?c=chat&a=login');
     } else {
         if (empty($_SESSION['nickName'])) {
             $mysql = CommonMysql::getInstance('localhost', 'root', '');
             $data = $mysql->query("select nickName from test.user where number=:number", array(':number' => $_SESSION['number']));
             if (!empty($data)) {
                 $_SESSION['nickName'] = $data[0]['nickName'];
             }
         }
         $user['number'] = $_SESSION['number'];
         $user['nickName'] = $_SESSION['nickName'];
         return $user;
     }
 }
 /**
  * 设置昵称
  */
 public function setNickName()
 {
     $this->outType = 'json';
     $number = $_SESSION['number'];
     $name = CommonRequest::getRequest('name');
     $mysql = CommonMysql::getInstance('localhost', 'root', '');
     $data = $mysql->query('select nickName from test.user where nickName=:name', array('name' => $name));
     if (!empty($data)) {
         $this->out = array('flag' => true, 'msg' => '该昵称已被占用!');
     } else {
         $mysql->execute("insert into test.user(number,nickName) value ('{$number}','{$name}')");
         $id = $mysql->getInsertID();
         if (!empty($id)) {
             $_SESSION['nickName'] = $name;
             $this->out = array('flag' => true, 'msg' => '该昵称已被占用!');
         } else {
             $this->out = array('flag' => false, 'msg' => '网络异常,请稍后重试!');
         }
     }
 }