Пример #1
0
 /**
  * 数据库查询函数
  *
  * @param string $sql 查询语句 
  * @return mixed
  */
 public static function query($sql)
 {
     $sql = trim($sql);
     if (self::$db == NULL) {
         self::_init_mysql();
     }
     self::$mysqli_rst = self::$db->query($sql);
     if (FALSE == self::$mysqli_rst) {
         echo 'MySQL query  errno : ' . self::$db->errno . PHP_EOL;
         $backtrace = debug_backtrace();
         var_dump($backtrace);
         return FALSE;
     } else {
         return self::$mysqli_rst;
     }
 }
Пример #2
0
 /**
  * 从MySQL中,查询未以此为标准抓取关注者的用户
  * 
  * @param int $limit 获取记录数量
  * @return mixed
  */
 private function _get_sql_users($limit = 20)
 {
     if (empty($limit)) {
         return FALSE;
     }
     $sql = "SELECT `username` FROM `user` WHERE `used`=0 LIMIT 20";
     $result = CG_DB::query($sql);
     $res_arr = array();
     if ($result->num_rows > 0) {
         while ($row = $result->fetch_assoc()) {
             $res_arr[] = $row['username'];
         }
     }
     $sql = "('" . implode($res_arr, "','") . "')";
     //标记为已经抓去过信息
     $sql = "UPDATE `user` SET `used`=1 WHERE `username` IN " . $sql;
     CG_DB::query($sql);
     // $result->free();
     return $res_arr;
 }