destoon 数据库操作

  2020-02-07    阅读:99
 1、插入数据

 $db->query("INSERT INTO ".get_table($mid)." ($sqlk) VALUES ($sqlv)");
 $itemid = $db->insert_id();

2、获取一条数据

$r = $db->get_one("SELECt COUNT(*) AS num FROM {$table} WHERe $condition order by statid desc");
  if($r['num']>0){
   exit('{"status":"0","msg":"重复"}');  
  }else{
   
  }

 

函数在include/db_mysql.class.php 中定义

function query($sql, $type = '', $ttl = 0, $save_id = false) {
  #echo $sql;echo '<br/>';
  $select = strtoupper(substr($sql, 0, 7)) == 'SELECT ' ? 1 : 0;
  if($this->ttl > 0 && $type == 'CACHE' && $select) {
   $this->cursor = 0;
   $this->cache_id = md5($sql);
   if($this->cids) $this->cache_ids[] = $this->cache_id;
   $this->result = array();
   $this->cache_ttl = ($ttl ? $ttl : $this->ttl) + mt_rand(-10, 30);
   return $this->_query($sql);
  }
  if(!$save_id) $this->cache_id = 0;
  $func = $type == 'UNBUFFERED' ? 'mysql_unbuffered_query' : 'mysql_query';
  if(!($query = $func($sql, $this->connid))) $this->halt('MySQL Query Error', $sql);
  $this->querynum++;
  return $query;
 }

 

function get_one($sql, $type = '', $ttl = 0) {
  $sql = str_replace(array('select ', ' limit '), array('SELECT ', ' LIMIT '), $sql);
  if(strpos($sql, 'SELECT ') !== false && strpos($sql, ' LIMIT ') === false) $sql .= ' LIMIT 0,1';
  $query = $this->query($sql, $type, $ttl);
  $r = $this->fetch_array($query);
  $this->free_result($query);
  return $r;
 }

function count($table, $condition = '', $ttl = 0) {
  global $DT_TIME;
  $sql = 'SELECT COUNT(*) as amount FROM '.$table;
  if($condition) $sql .= ' WHERe '.$condition;
  $r = $this->get_one($sql, $ttl ? 'CACHE' : '', $ttl);
  return $r ? $r['amount'] : 0;
 }

 function fetch_array($query, $result_type = MYSQL_ASSOC) {
  return $this->cache_id ? $this->_fetch_array($query) : mysql_fetch_array($query, $result_type);
 }

 function affected_rows() {
  return mysql_affected_rows($this->connid);
 }

 function num_rows($query) {
  return mysql_num_rows($query);
 }

 function num_fields($query) {
  return mysql_num_fields($query);
 }

 function result($query, $row) {
  return @mysql_result($query, $row);
 }

 function free_result($query) {
  if(is_resource($query) && get_resource_type($query) === 'mysql result') {
   return @mysql_free_result($query);
  }
 }

 function insert_id() {
  return mysql_insert_id($this->connid);
 }

 function fetch_row($query) {
  return mysql_fetch_row($query);
 }

 

免责声明:
本站部份内容系网友自发上传与转载,不代表本网赞同其观点;
如涉及内容、版权等问题,请在30日内联系,我们将在第一时间删除内容!

(c)2012-2023 www.qiyeyunshang.com All Rights Reserved.
慧一科技destoon模板   辽ICP备2021002520号-1
  QQ咨询

购买模板 售前咨询

  咨询QQ

3292628658
(早8:30-晚10:00)

  微信咨询

咨询微信
客服微信

  返回顶部