public static function getUserById($uid)
 {
     $uid = (int) $uid;
     if ($uid <= 0) {
         return '';
     }
     $sql = "SELECT * FROM `user` WHERE `id` = '" . $uid . "'";
     return DBMysqli::getInstance()->getRow($sql);
 }
Beispiel #2
0
 private function __construct($config = null)
 {
     self::$_CONFIG = empty($config) ? DBConfig::$MYSQL_MASTER_SERVER : $config;
     try {
         $this->_link = new mysqli(self::$_CONFIG['host'], self::$_CONFIG['username'], self::$_CONFIG['password'], self::$_CONFIG['database'], self::$_CONFIG['port'] ? intval(self::$_CONFIG['port']) : 3306);
         if ($this->_link) {
             $this->_link->set_charset('utf8');
         }
     } catch (Exception $e) {
         Log::error($e->getMessage() . mysqli_connect_errno(), 'Mysqli');
     }
 }
 /**
  * 
  * @brief 分页
  * @param unknown_type $model
  * @param unknown_type $pageSize
  * @param unknown_type $map
  * @param unknown_type $order
  * @param unknown_type $join
  * @param unknown_type $field
  */
 public static function showPage($majory, $order = 'puid', $limit = 30)
 {
     $field = self::_getFields();
     $where = "`majory_id` = {$majory['id']}";
     $sqlCount = "SELECT count(*) as count FROM " . self::$TABLE_DIARY . " WHERE {$where}";
     $page = HttpNamespace::getGET('p', 1);
     $offset = ($page - 1) * $limit;
     $sql = "SELECT " . implode(',', $field) . " FROM " . self::$TABLE_DIARY . " WHERE {$where} ORDER BY `" . $order . "` desc LIMIT {$offset},{$limit}";
     $num = DBMysqli::getInstance()->getRow($sqlCount);
     $page = new Page($num['count'], $limit);
     $result[] = $page->show();
     $result[] = DBMysqli::getInstance()->getAll($sql);
     return $result;
 }
 /**
  * 取得实例
  * 
  * @access public
  * @param mixed $dbinfo
  * @return mixed
  */
 public static function getInstance($dbinfo)
 {
     self::$dbinfo = $dbinfo;
     if (!self::$dbo instanceof self) {
         self::$conn = mysql_connect($dbinfo['host'], $dbinfo['user'], $dbinfo['password']);
         if (self::$conn === false) {
             trigger_error('<span style="color:red;border:red 1px solid;padding:0.5em;">无法连接数据库,请检查数据库连接参数!</span>', E_USER_ERROR);
             exit;
         }
         $charset = isset($dbinfo['charset']) ? $dbinfo['charset'] : 'utf8';
         mysql_query("set names '{$charset}'");
         mysql_select_db($dbinfo['name'], self::$conn);
         self::$dbo = new self();
     }
     return self::$dbo;
 }
 public function defaultAction()
 {
     $content = addslashes(HttpNamespace::getPOST('content'));
     $puid = HttpNamespace::getPOST('puid');
     $backUrl = UrlNamespace::detailUrl(self::$MAJORY['id'], $puid);
     if (empty(self::$CATEGORY)) {
         $error = ErrorConfig::EMPTY_VALUE;
         if (strpos($backUrl, '?') === false) {
             $backUrl .= '?error=' . $error;
         }
         $backUrl .= '&error=' . $error;
         HttpNamespace::redirect($backUrl);
     }
     if (empty($content)) {
         //error = 1
         $error = ErrorConfig::EMPTY_VALUE;
         if (strpos($backUrl, '?') === false) {
             $backUrl .= '?error=' . $error;
         }
         $backUrl .= '&error=' . $error;
         HttpNamespace::redirect($backUrl);
     }
     if (isset($_SESSION['login']) && $_SESSION['login']) {
         $userId = $_SESSION['user']['id'];
         $nick_name = addslashes($_SESSION['user']['nick_name']);
     } else {
         $userId = 0;
         $nick_name = '匿名用户';
     }
     $ua = 0;
     $sql = "INSERT INTO " . self::$CATEGORY['table'] . "_comment (`puid`,`user_id`,\n               `nick_name`,`content`,`times`,`ua`)VALUES({$puid},{$userId},'" . $nick_name . "',\n               '" . $content . "'," . time() . ",{$ua})";
     if (DBMysqli::getInstance()->execute($sql) > 0) {
         $sql = "UPDATE " . self::$CATEGORY['table'] . " set comment_times=comment_times+1,weight=weight+1 WHERE puid={$puid}";
         DBMysqli::getInstance()->execute($sql);
     }
     HttpNamespace::redirect($backUrl);
 }
Beispiel #6
0
     * Return next sequence from sequence table
     * This method use only mysql
     * @return int
     */
    function db_insert_id()
    {
        $connection = $this->_getConnection('master');
        return mysqli_insert_id($connection);
    }
    /**
     * Fetch a result row as an object
     * @param resource $result
     * @return object
     */
    function db_fetch_object(&$result)
    {
        return mysqli_fetch_object($result);
    }
    /**
     * Free result memory
     * @param resource $result
     * @return boolean Returns TRUE on success or FALSE on failure.
     */
    function db_free_result(&$result)
    {
        return mysqli_free_result($result);
    }
}
DBMysqli::$isSupported = function_exists('mysqli_connect');
/* End of file DBMysqli.class.php */
/* Location: ./classes/db/DBMysqli.class.php */
<?php

include_once '../db/DbMysqli.php';
$obj = new DBMysqli('127.0.0.1', 'root', 'root');
$obj->setDb('dapp');
//删除数据测试
$result = $obj->deleteData('baby', ['name' => 'jin']);
var_dump($result);
//插入数据测试
//$result = $obj->insertData('baby',['name'=>'tao']);
//var_dump($result);
//查询多条数据测试
$result = $obj->getDataList('baby', 'baby_id,name', ['name' => 'tao']);
//var_dump($result);
//更新数据测试
$result = $obj->updateData('baby', ['gender' => 2], ['name' => 'tao']);
var_dump($result);
 public static function getNameById($id)
 {
     $sql = "SELECT * FROM `image` WHERE `id`={$id}";
     return DBMysqli::getInstance()->getRow($sql);
 }
 private function _getHospitalById($id)
 {
     $sql = "SELECT * FROM hospital_post WHERE `id` = " . $id;
     return DBMysqli::getInstance()->getRow($sql);
 }
 private function _getDistrictById($districtId)
 {
     $sql = "SELECT * FROM district WHERE `district_id` = " . $districtId;
     return DBMysqli::getInstance()->getRow($sql);
 }
Beispiel #11
0
 /**
 @brief
 @developer
 @return
 @access
 @param $target_name
 */
 public function isTableExists($target_name)
 {
     parent::isTableExists($target_name);
     return FALSE;
 }