mysql資料庫計數器 簡單易用的計數器(資料庫)

2021-10-18 02:37:38 字數 2602 閱讀 2422

簡單易用的計數器(資料庫)次用法

include("counter.php");

counter(__file__);//為檔案增加乙個計數

if($php_self=="/index.php")

$count=counter("index_count");//為首頁增加乙個計數

else

$count=counter("index_count","",0);//取得首頁計數

echo "你是第$count個訪問者";

--------counter.php-----------

if(!isset($php_include_counter_php))

{$php_include_counter_php=__file;

$counter_error_state=0;

$counter_error_msg="";

function counter($file,$query="",$add=1)

$db_name="database";

$db_user="username";

$db_pass="password";

$db_table="counter";

if(empty($file))

$counter_error_state=-100;

$counter_error_msg="缺少第乙個引數或引數為空";

return -100;

global $php_self,$query_string,$counter_error_state,$counter_error_msg;

if(empty($db_user)||!$db_user||$db_user=="")[email protected]_connect("localhost");

else [email protected]_connect("localhost",$db_user,$db_pass);

if(!$res)

$counter_error_states=-10;

$counter_error_msg="不能連線資料庫";

return -10;

if([email protected]_select_db($db_name))

$counter_error_states=-11;

$counter_error_msg="不能選擇資料庫";

return -11;

else

if([email protected]_query("select * from ".$db_table))

if([email protected]_query("create table ".$db_table." (id integer auto_increment,primary key (id),file varchar(255),query varchar(255),time varchar(255),count int)"))

$counter_error_states=-20;

$counter_error_msg="不能建立資料表";

return -20;

@mysql_free_result($db_res);

$str="select * from ".$db_table." where file=\"".$file."\" and query=\"".$query."\"";

if([email protected]_query($str))

$counter_error_states=-30;

$counter_error_msg="不能查詢記錄";

return -30;

[email protected]_num_rows($db_res);

if($num>1)

$counter_error_states=-40;

$counter_error_msg="發生沒有預期的錯誤=資料行數錯誤";

return -40;

$count=0;

$str="insert ";

$strwhere="";

if($num==1)

[email protected]_fetch_array($db_res);

@mysql_free_result($db_res);

$count=$row["count"];

$id=$row["id"];

$str="update ";

$strwhere=" where id=$id";

if($add<1)return $count;

$count+=$add;

$str.=$db_table." set file=\"".$file."\",query=\"".$query."\",time=\"".date("y;n;d;g;i;s")."\",count=".$count.$strwhere;

[email protected]_query($str);

if(!$db_res)

$counter_error_states=-50;

$counter_error_msg="不能新增或更新記錄";

return -50;

return $count;

簡單易用的計數器(資料庫)

用法 include counter.php 做為現在的主流開發語言 counter file 為檔案增加乙個計數 if php 做為現在的主流開發語言 self index.php 做為現在的主流開發語言 else echo 你是第 count個訪問者 counter.php 做為現在的主流開發語...

蝴蝶計數器 乙個簡單易用的網頁計數器

有懂前端的小夥伴對這個專案感興趣可以聯絡我哦 2020年4月29號 統計部落格訪問量突破1000000!2020年3月22號 蝴蝶計數器網域名稱正式更改為 www.bfcounter.vip 2020年2月20號 總使用者量243 統計部落格訪問量 589056次!2019年10月30號 蝴蝶計數器...

mysql計數 mysql實現計數器

本文 如果是在非常高的併發之下,還是建議用記憶體資料庫redis去實現計數的功能。如果不是那麼高的併發,用表實現就可以。drop table access counter create table access counter cnt int unsigned not null insert int...