日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
如何正確理解PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)

在運(yùn)用PHP語言對數(shù)據(jù)庫進(jìn)行操作的時候,我們將會用到mysql_X這一函數(shù)庫。下面我們將為大家詳細(xì)介紹有關(guān)PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)的函數(shù)。#t#

創(chuàng)新互聯(lián)是一家專業(yè)提供互助企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、HTML5、小程序制作等業(yè)務(wù)。10年已為互助眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡(luò)公司優(yōu)惠進(jìn)行中。

PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之 mysql_result()

mixed mysql_result(resource result_set, int row [,mixed field])
從result_set 的指定row 中獲取一個field 的數(shù)據(jù). 簡單但是效率低.

舉例:

  1. $link1 = @mysql_connect("server1", 
    "webuser", "password") 
  2. or die("Could not connect 
    to mysql server!");
  3. @mysql_select_db("company") 
    or die("Could not select database!");
  4. $query = "select id, name 
    from product order by name"; 
  5. $result = mysql_query($query);
  6. $id = mysql_result($result, 0, "id");
  7. $name = mysql_result($result, 0, "name");
  8. mysql_close(); 

注意,上述代碼只是輸出結(jié)果集中的***條數(shù)據(jù)的字段值,如果要輸出所有記錄,需要循環(huán)處理.

 
 
 
  1. for ($i = 0; $i <= mysql_num_rows($result); $i++)
  2. {
  3. $id = mysql_result($result, 0, "id");
  4. $name = mysql_result($result, 0, "name");
  5. echo "Product: $name ($id)";
  6. }

注意,如果查詢字段名是別名,則mysql_result中就使用別名.

PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_row()

array mysql_fetch_row(resource result_set)
從result_set中獲取整行,把數(shù)據(jù)放入數(shù)組中.
舉例(注意和list 的巧妙配合):

 
 
 
  1. $query = "select id, 
    name from product order by name"; 
  2. $result = mysql_query($query);
  3. while(list($id, $name) 
    = mysql_fetch_row($result)) {
  4. echo "Product: $name ($id)";
  5. }

PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_array()

array mysql_fetch_array(resource result_set [,int result_type])
mysql_fetch_row()的增強(qiáng)版.
將result_set的每一行獲取為一個關(guān)聯(lián)數(shù)組或/和數(shù)值索引數(shù)組.
默認(rèn)獲取兩種數(shù)組,result_type可以設(shè)置:
MYSQL_ASSOC:返回關(guān)聯(lián)數(shù)組,字段名=>字段值
MYSQL_NUM:返回數(shù)值索引數(shù)組.
MYSQL_BOTH:獲取兩種數(shù)組.因此每個字段可以按索引偏移引用,也可以按字段名引用.

舉例:

 
 
 
  1. $query = "select id,
     name from product order by name";
  2. $result = mysql_query($query);
  3. while($row = mysql_fetch_array
    ($result, MYSQL_BOTH)) { 
  4. $name = $row['name'];
  5. //或者 $name = $row[1];
  6. $name = $row['id'];
  7. //或者 $name = $row[0];
  8. echo "Product: $name ($id)";
  9. }

PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_assoc()

array mysql_fetch_assoc(resource result_set)
相當(dāng)于 mysql_fetch_array($result, MYSQL_ASSOC)

PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_object()

object mysql_fetch_object(resource result_set)
和mysql_fetch_array()功能一樣,不過返回的不是數(shù)組,而是一個對象.
舉例:

 
 
 
  1. $query = "select id, name 
    from product order by name";
  2. $result = mysql_query($query); 
  3. while($row = mysql_fetch_object
    ($result)) {
  4. $name = $row->name;
  5. $name = $row->id;
  6. echo "Product: $name ($id)";
  7. }

以上這些函數(shù)就是PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)的全部總結(jié)。


分享標(biāo)題:如何正確理解PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)
鏈接分享:http://www.dlmjj.cn/article/djdgjgs.html