用PHP和MYSQL建立计数器过程详解
2008-05-01 03:53
651 查看
运行MYSQL.EXE
MYSQL> create database counter;
Query OK, 1 row affected (0.10 sec)
MYSQL> use counter;
Database changed
MYSQL> create table tl(id integer(2),count integer(5));
Query OK, 0 rows affected (0.21 sec)
MYSQL> show columns from tl;
+-------+--------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------+------+-----+---------+-------+
| id | int(2) | YES | | NULL | |
| count | int(5) | YES | | NULL | |
+-------+--------+------+-----+---------+-------+
2 rows in set (0.05 sec)
MYSQL> select * from tl;
Empty set (0.08 sec)
MYSQL> insert into tl(id,count) values(1,1);
Query OK, 1 row affected (0.02 sec)
MYSQL> select * from tl;
+------+-------+
| id | count |
+------+-------+
| 1 | 1 |
+------+-------+
1 row in set (0.03 sec)
下面编写HTML文件内容:
<html>
<body>
<?PHP
$myvar = "来访人数:";
echo $myvar;
?>
<?PHP
MYSQL_connect() or die("there are problems to connect to MYSQL!");
$query="select * from tl";
$result=MYSQL_db_query("counter",$query);
if($result){
$r=MYSQL_fetch_array($result);
$counter=$r["count"];
$counter=$counter+1;
echo $counter;
$query="update tl set count='$counter' where id=1";
$result=MYSQL_db_query("counter",$query);
MYSQL_close();
}
?>
</body>
</html>
MYSQL> create database counter;
Query OK, 1 row affected (0.10 sec)
MYSQL> use counter;
Database changed
MYSQL> create table tl(id integer(2),count integer(5));
Query OK, 0 rows affected (0.21 sec)
MYSQL> show columns from tl;
+-------+--------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------+------+-----+---------+-------+
| id | int(2) | YES | | NULL | |
| count | int(5) | YES | | NULL | |
+-------+--------+------+-----+---------+-------+
2 rows in set (0.05 sec)
MYSQL> select * from tl;
Empty set (0.08 sec)
MYSQL> insert into tl(id,count) values(1,1);
Query OK, 1 row affected (0.02 sec)
MYSQL> select * from tl;
+------+-------+
| id | count |
+------+-------+
| 1 | 1 |
+------+-------+
1 row in set (0.03 sec)
下面编写HTML文件内容:
<html>
<body>
<?PHP
$myvar = "来访人数:";
echo $myvar;
?>
<?PHP
MYSQL_connect() or die("there are problems to connect to MYSQL!");
$query="select * from tl";
$result=MYSQL_db_query("counter",$query);
if($result){
$r=MYSQL_fetch_array($result);
$counter=$r["count"];
$counter=$counter+1;
echo $counter;
$query="update tl set count='$counter' where id=1";
$result=MYSQL_db_query("counter",$query);
MYSQL_close();
}
?>
</body>
</html>
相关文章推荐
- 用PHP和MYSQL建立计数器过程详解
- 用PHP和MYSQL建立计数器过程详解
- 用PHP和MYSQL建立计数器过程详解
- 用PHP和MYSQL建立计数器过程详解
- mysql存储过程详解以及PHP调用MYSQL存储过程实例
- php下操作mysql详解之初级!(面向对象,面向过程)
- centos6.4+nginx+mysql+php+phpmyadmin整合过程详解
- MySQL存储过程详解和PHP操作示例
- php调用mysql存储过程的详解
- 基于apache + mysql + php编译安装过程详解
- Ubuntu下Apache+PHP+MySQL安装过程详解
- window 下安装nginx、php 、mysql过程及配置详解
- 基于Php mysql存储过程的详解
- 基于Php mysql存储过程的详解
- php中的pdo之mysql预处理语句与存储过程详解
- 基于apache + mysql + php编译安装过程详解
- 详解 CentOS 安装配置 Nginx 0.8.33+PHP 5.3.1+php-fpm+MySQL 全过程【转】
- LinuxPHP详解和mysql初探
- PHP调用MySQL存储过程并返回值的方法