Home>
<?php
 header ("content-type:text/html;charset=utf-8");
 include "lib/mysql.class.php";
 $mysql_obj=mysql ::getconn ();
 if (class_exists ("redis")) {
  //redis
  $redis=new redis ();
  $redis->pconnect ("127.0.0.1", 6379);
  if (isset ($_ server ["http_referer"])) {
   $url_md5=md5 ($_ server ["http_referer"]);
  }
  $adve_key="adve";
  $adve_key_exists="adve_exists";
  if (! $redis->exists ($adve_key_exists)) {
   $list=$mysql_obj->fetch_array ("select * from admin_online_adve");
   if ($list) {
    foreach ($list as $key =>$value) {
     $url_hash=md5 ($value ["adve_url"]);
     $adve_hash_key=$adve_key. ":". $url_hash;
     $id=$value ["id"];
     $redis->set ($adve_hash_key, $id);
     $redis->set ($adve_key_exists, true);
    }
   }
  }
  $adve_new_key=$adve_key. ":". $url_md5;
  if ($redis->exists ($adve_new_key)) {
    $adve_plus=$adve_new_key. ":plus";
    if (! $redis->exists ($adve_plus)) {
     $redis->set ($adve_plus, 1);
    } else {
     $redis->incr ($adve_plus);
     $num=$redis->get ($adve_plus);
     if ($num>100) {
      $id=$redis->get ($adve_new_key);
      //insert to sql;
      $mysql_obj->query ("update admin_online_adve set adve_num=adve_num + $num where id=$id");
      $redis->set ($adve_plus, 1);
     }
    }
  }
 }
?>
<html>
<head>
<Meta http-equiv="refresh" content="1;url=https://itunes.apple.com/cn/app/san-guo-zhi15-ba-wangno-da-lu/id694974270?mt=8 ">
<title>Statistics</title>
</head>
<body>
 <img src="loading.gif">loading ...
</body>
</html>

The php connection mysql class mysql.class.php is as follows:

<?php
define ("mysql_sql_getdata", 1);
define ("mysql_sql_execute", 2);
class mysql_db {
  var $_server;//Database server address
  var $_user;//Database connection account
  var $_password;//Database connection password
  var $_dbname;//database name
  var $_persistency=false;//Whether to use persistent connection
  var $_isconnect=false;//whether a database connection has been established
  var $_charset="utf8";//Database connection character set
  var $_isdebug=false;//whether debug mode
  var $_sql=array ();//Execute array of SQL statements
  var $_db_connect_id;//Database connection object ID
  var $_result;//The value returned by executing the query
  var $_record;
  var $_rowset;
  var $_errno=0;
  var $_error="connection error";
  var $_checkdb=false;
  function mysql_db ($dbserver, $dbuser, $dbpassword, $database, $persistency=false, $autoconnect=false, $checkdb=false)
  {
    $this->_server=$dbserver;
    $this->_user=$dbuser;
    $this->_password=$dbpassword;
    $this->_dbname=$database;
    $this->_persistency=$persistency;
    $this->_autoconnect=$autoconnect;
    $this->_checkdb=$checkdb;
    if ($autoconnect) {
      $this->connection ();
    }
  }
  function connection ($newlink=false)
  {
    if (! $newlink) {
      if ($this->_isconnect&&isset ($this->_db_connect_id)) {
        @mysql_close ($this->_db_connect_id);
      }
    }
    $this->_db_connect_id=($this->persistency)?@mysql_pconnect ($this->_server, $this->_user, $this->_password):@mysql_connect ($this->_server, $this->_user, $this->_password, $newlink);
    if ($this->_db_connect_id)
    {
      if ($this->version ()>"4.1")
      {
        if ($this->_charset!="")
        {
          @mysql_query ("set names" ".str_replace ("-"," ", $this->_charset)." "", $this->_db_connect_id);
        }
      }
      if ($this->version ()>"5.0")
      {
        @mysql_query ("set sql_mode =" "", $this->_db_connect_id);
      }
      //Check if the specified database is successfully connected
      if ($this->_checkdb) {
        $dbname=mysql_query ("select database ()", $this->_db_connect_id);
        $dbname=mysql_fetch_array ($dbname, mysql_num);
        $dbname=trim ($dbname [0]);
      } else {
        $dbname="";
      }
      if ($dbname == $this->_dbname || $dbname == "") {
        if (! @mysql_select_db ($this->_dbname, $this->_db_connect_id))
        {
          @mysql_close ($this->_db_connect_id);
          $this->_halt ("cannot use database". $this->_dbname);
        }
      } else {
        if ($this->_checkdb&&! $newlink) {
          $this->connection (true);
        }
      }
      return true;
    }
    else
    {
      $this->_halt ("connect failed.", false);
    }
  }
  function setcharset ($charset) {
    //$charset=str_replace ("-", "", $charset);
    $this->_charset=$charset;
  }
  function setdebug ($isdebug=true) {
    $this->_isdebug=$isdebug;
  }
  function query ($sql, $type="")
  {
    return $this->_ runsql ($sql, mysql_sql_getdata, $type);
  }
  function execute ($sql)
  {
    return $this->_ runsql ($sql, mysql_sql_execute, "unbuffered");
  }
  function _runsql ($sql, $sqltype=mysql_sql_getdata, $type="")
  {
    if ($type == "unbuffered") {
      $this->[email protected]_unbuffered_query ($sql, $this->_ db_connect_id);
    } else {
      $this->[email protected]_query ($sql, $this->_ db_connect_id);
    }
    //Save and execute the SQL statement in test mode
    if ($this->_isdebug) {
      $this->_sql []=$sql;
    }
    if ($this->_result)
    {
      return $sqltype == mysql_sql_getdata?$this->getnumrows ():$this->getaffectedrows ();
    } else {
      $this->_halt ("invalid sql:". $sql);
      return false;
    }
  }
  function next ($result_type=mysql_assoc) {
    $this->fetchrow ($result_type);
    return is_array ($this->_ record);
  }
  function f ($name) {
    if (is_array ($this->_ record)) {
      return $this->_record [$name];
    } else {
      return false;
    }
  }
  function fetchrow ($result_type=mysql_assoc)
  {
    if ($this->_result)
    {
      $this->[email protected]_fetch_array ($this->_ result, $result_type);
      return $this->_record;
    } else {
      return false;
    }
  }
  function getall ($sql, $primarykey="", $result_type=mysql_assoc)
  {
    if ($this->_runsql ($sql, mysql_sql_getdata)>= 0) {
      return $this->fetchall ($primarykey, $result_type);
    } else {
      return false;
    }
  }
  function getone ($sql, $result_type=mysql_assoc)
  {
    if ($this->_ runsql ($sql, mysql_sql_getdata)>0) {
      $arr=$this->fetchall ("", $result_type);
      if (is_array ($arr)) {
        return $arr [0];
      }
    } else {
      return false;
    }
  }
  function fetchall ($primarykey="", $result_type=mysql_assoc)
  {
    if ($this->_result)
    {
      $i=0;
      $this->_rowset=array ();
      if ($primarykey == "")
      {
        while ($this->next ($result_type))
        {
          $this->_rowset [$i]=$this->_record;
          $i ++;
        }
      } else {
        while ($this->next ($result_type))
        {
          $this->_rowset [$this->f ($primarykey)]=$this->_record;
          $i ++;
        }
      }
      return $this->_rowset;
    } else {
      //$this->_halt ("invalid result");
      return false;
    }
  }
  function checkexist ($sql)
  {
    return $this->query ($sql)>0?true:false;
  }
  function getvalue ($sql, $colset=0)
  {
    if ($this->query ($sql)>0) {
      $this->next (mysql_both);
      return $this->f ($colset);
    } else {
      return false;
    }
  }
  function getnumrows ()
  {
    return @mysql_num_rows ($this->_ result);
  }
  function getnumfields ()
  {
    return @mysql_num_fields ($this->_ result);
  }
  function getfiledname ($offset)
  {
    return @mysql_field_name ($this->_result, $offset);
  }
  function getfiledtype ($offset)
  {
    return @mysql_field_type ($this->_result, $offset);
  }
  function getfiledlen ($offset)
  {
    return @mysql_field_len ($this->_result, $offset);
  }
  function getinsertid ()
  {
    return @mysql_insert_id ($this->gt__db_connect_id);
  }
  function getaffectedrows ()
  {
    return @mysql_affected_rows ($this->gt__db_connect_id);
  }
  function free_result ()
  {
    [email protected]_free_result ($this->_ result);
    $this->_result=0;
    return $ret;
  }
  function version () {
    return @mysql_get_server_info ($this->_ db_connect_id);
  }
  function close () {
    return @mysql_close ($this->_db_connect_id);
  }
  function sqloutput ($isout=true, $all=true) {
    if ($all) {
      $ret=implode ("<br>", $this->_sql);
    } else {
      $ret=$this->_ sql [count ($this->_ sql) -1];
    }
    if ($isout) {
      echo $ret;
    } else {
      return $ret;
    }
  }
  function _halt ($msg="session halted.", $geterr=true) {
    if ($this->_isdebug) {
      if ($geterr) {
        $this->[email protected]_errno ($this->_ db_connect_id);
        $this->[email protected]_error ($this->_ db_connect_id);
        printf ("<b>mysql_error</b> ;:%s (%s)<br></font>/n", $this->_errno, $this->_error);
      }
      die ($msg);
    } else {
      die ("session halted.");
    }
  }
}
?>
php
  • Previous Learn with me JavaScript prototypes, getPrototypeOf and __proto__
  • Next In-depth analysis of the relationship between prototype and proto in JavaScript