search
Homephp教程php手册基于文件、数据库的计数器

基于文件、数据库的计数器

Jun 13, 2016 am 10:25 AM
authorOriginalbased ondatabasedocumentofcounter

作者:javaduke,原创于www.dukejava.com
基于文件的php计数器
〈?
//php计数器,基于文件系统。
function wincounter(){
//如果文件不存在,创建之
if(!file_exists("count.txt"))
{
exec("echo 0>count.txt");
}
//打开我们的记录文件
//得到文件大小然后依据这个文件的大小取出需要的数据
$fp=fopen("count.txt","r+);
$FileSize=filesize("count.txt");
$Count=fgets($fp,$FileSize+1);
//将记录数加上1以后存回文件中
$Count+=1;
fseek($fp,$Count);
fclose($fp);
//返回现在的访问数
return $Count;
}
?〉
基于数据库的计数器(mysql)?
1、首先创建数据库:
CREATE TABLE counter{
counter int not null,
id int not null
}
INSERT INTO counter(counter,id) VALUES(0,1)
2、计数器代码:
〈?
//PHP计数器,基于MySQL数据库服务器。
function linuxcounter(){
//连接MySQL数据库
$conn=mysql_connect("localhost",phpbook","");
//查询当前浏览数
//注意取得结果的方式
$sql="select*from counter";
$result=mysql_query($sql,$conn);


$objResult=mysql_fetch_object($result);
$count=$objResult->counter;
//更新数据库,并返回当前浏览数作为结果
$sql="update counter set counter=".($cont+1)." where id=1";
mysql_query($sql,$conn);
mysql_close($conn);
return $count+1;
}
?〉
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools