当前位置:数据库 > SQLServer >>

用PHP和MYSQL建立计数器过程详解

运行MySQL(和PHP搭配之最佳组合).EXE
MySQL(和PHP搭配之最佳组合)> create database counter;
Query OK, 1 row affected (0.10 sec)

MySQL(和PHP搭配之最佳组合)> use counter;
Database changed

MySQL(和PHP搭配之最佳组合)> create table tl(id integer(2),count integer(5));
Query OK, 0 rows affected (0.21 sec)

MySQL(和PHP搭配之最佳组合)> 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(和PHP搭配之最佳组合)> select * from tl;
Empty set (0.08 sec)

MySQL(和PHP搭配之最佳组合)> insert into tl(id,count) values(1,1);
Query OK, 1 row affected (0.02 sec)

MySQL(和PHP搭配之最佳组合)> select * from tl;
+------+-------+
| id   | count |
+------+-------+
|    1 |     1 |
+------+-------+
1 row in set (0.03 sec)

下面编写HTML文件内容:


<html>
<body>

<?php(做为现在的主流开发语言)
$myvar = "来访人数:";
echo $myvar;
?>

<?php(做为现在的主流开发语言)
 MySQL(和PHP搭配之最佳组合)_connect() or die("there are problems to connect to MySQL(和PHP搭配之最佳组合)!");
 $query="select * from tl";
 $result=MySQL(和PHP搭配之最佳组合)_db_query("counter",$query);
 if($result){
  $r=MySQL(和PHP搭配之最佳组合)_fetch_array($result);
  $counter=$r["count"];
  $counter=$counter+1;
  echo $counter;
  $query="update tl set count=$counter where id=1";
  $result=MySQL(和PHP搭配之最佳组合)_db_query("counter",$query);
  MySQL(和PHP搭配之最佳组合)_close();
 }
?>
</body>
</html>

补充:Web开发 , php ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,