国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

從一個MysqL的例子來學習查詢語句

2024-07-24 12:57:23
字體:
來源:轉載
供稿:網友
自上學這么多年以來,得出了從一個例子入手來學習是最快最有效,并能培養出很強的實踐能力,這是一種很

好的學習方法。不訪試試。比如看一本書的時候從各章節的例子入手,找出不了解的以及不懂的還是新知識,

進而有針對性的學習。看看下面的例子:

<?php
$ip = getenv("REMOTE_ADDR");
//echo "$ip";
$conn=MySQL_connect('ip','root','****');
  mysql_select_db('db',$conn);
         $sql="select *from counter where ip=/"$ip/";";
         $result=mysql_query($sql,$conn);  
$num=mysql_num_rows($result);
$count=mysql_query("select*from counter",$conn);
$count=mysql_num_rows($count);
//echo "$num";
//echo "$count";
if($num==0)
{
$sum=1;
$count++;
$sql="insert into counter(ip,sum,countdata)values('$ip','1','$count')";
mysql_query($sql,$conn);  
mysql_close($conn);  
//echo "$count";
}
else
{
$my="select sum from counter where ip='$ip'";

$bbbbbb=mysql_query($my) or die(mysql_error());
$row=mysql_fetch_Array($bbbbbb);
@$sum=$row[sum];
//echo "$sum";
$sum++;
$sql="update counter set sum='$sum' where ip='$ip'";
  mysql_query($sql);  
  mysql_close($conn);  
}
$str_count=strval($count);
   $str_count=Chop($str_count);
   $count_len=strlen($str_count);
   $image_count="";
   if($count_len<6)
   {for($j=0;$j<6-$count_len;$j++)
   {$image_count=$image_count."<img src='0.gif'>";
   }
}
for($i=0;$i<$count_len;$i++)
{
$nom=substr($str_count,$i,1);
$image_count = $image_count."<img src='";
$image_count = $image_count.$nom;
$image_count = $image_count.".gif'>";
}
echo"$image_count<br>";
PRint"這是你的第".$sum."次訪問";
?>


從上面的一個小小的計數器例子來看。已經包括了查詢、插入、修改的知識。可以實現功能。記錄每一個IP的

訪問量及總的訪問次數。總量不支刷新

一、查詢:
   SELECT被用來檢索從一個或多個表中精選的行。select_expression指出你想要檢索的列。SELECT也可以用

來檢索不引用任何表的計算行
1、select*from table1;
2、select field1,field2 from table1;
3、select count(*)from table2;
4、select table1.filed1,table2.filed2 from table1,table2 where table1.field1='valed1';
5、select *from table1 where field1='valed1' and fiels2='valed2' orded by field1;
6、select*from table1 where filed1='valed1' order byfiled1 desc linit n;
7、select *from table2 where name like '%$lin%';(模糊)
8、sub_selects(高級)
select *from table1 where id In(select id from table2......);
9、select ...into table...(高級)
(可用select...into outfile...;insert...selkect...替代)
10、SELECT MAX(field1) AS field1 FROM table1 列的最大值
其中:表:table /字段:field

二、修改:
"update table1 set field1='value1',field2=value2'where fiels3='values3";
    UPDATE用新值更新現存表中行的列,SET子句指出哪個列要修改和他們應該被給定的值,WHERE子句,如果

給出,指定哪個行應該被更新,否則所有行被更新。

三、插入:
1、insert into table1 values('field1',field2',...);
   INSERT ... VALUES形式的語句基于明確指定的值插入行.
2、replace into tbl_name(1,2,3)values('1','2','3');
   REPLACE功能與INSERT完全一樣,除了如果在表中的一個老記錄具有在一個唯一索引上的新記錄有相同的值

,在新記錄被插入之前,老記錄被刪除。

四、刪除:
$a="delet from table1 where field1='$value1' and field2='$value2'";
   DELETE從tbl_name表中刪除滿足由where_definition給出的條件的行,并且返回刪除記錄的個數。如果你執

行一個沒有WHERE子句的DELETE,所有行都被刪除。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 弥渡县| 夹江县| 威海市| 岳阳市| 登封市| 嘉荫县| 桃园市| 延长县| 福鼎市| 深圳市| 盈江县| 开封县| 汾阳市| 深泽县| 东光县| 镇原县| 桃源县| 游戏| 临汾市| 葵青区| 静乐县| 谷城县| 喀喇| 乌拉特中旗| 侯马市| 宁武县| 云南省| 区。| 湖北省| 武鸣县| 绥宁县| 阜阳市| 石河子市| 当雄县| 全南县| 古丈县| 凌海市| 长治市| 阿城市| 临清市| 夏邑县|