日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第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ù)

這篇文章將為大家詳細講解有關(guān)PHP中怎么獲取顯示數(shù)據(jù)庫數(shù)據(jù),文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

創(chuàng)新互聯(lián)2013年開創(chuàng)至今,先為阜寧等服務(wù)建站,阜寧等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為阜寧企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

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)處理.

for ($i = 0; $i <= mysql_num_rows($result); $i++)  {  $id = mysql_result($result, 0, "id");  $name = mysql_result($result, 0, "name");  echo "Product: $name ($id)";  }

注意,如果查詢字段名是別名,則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)";  

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

array mysql_fetch_array(resource result_set [,int result_type])
mysql_fetch_row()的增強版.
將result_set的每一行獲取為一個關(guān)聯(lián)數(shù)組或/和數(shù)值索引數(shù)組.
默認獲取兩種數(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)";  

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

array mysql_fetch_assoc(resource result_set)
相當于 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)";  

關(guān)于PHP中怎么獲取顯示數(shù)據(jù)庫數(shù)據(jù)就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。


名稱欄目:PHP中怎么獲取顯示數(shù)據(jù)庫數(shù)據(jù)
當前地址:http://www.dlmjj.cn/article/jgedii.html