基于文件、数据库的计数器_PHP
Jun 01, 2016 pm 12:28 PM
counter
based on
database
document
counter
计数器
原创于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 of this Website
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 Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How does Go language implement the addition, deletion, modification and query operations of the database?

Detailed tutorial on establishing a database connection using MySQLi in PHP

How does Hibernate implement polymorphic mapping?

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

Full analysis of Go language file renaming operation

An in-depth analysis of how HTML reads the database

Analysis of the basic principles of MySQL database management system

Tips and practices for handling Chinese garbled characters in databases with PHP
