新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
講解PHP獲取字段屬性技巧
在進(jìn)行WEB開(kāi)發(fā)中,總會(huì)遇到與數(shù)據(jù)庫(kù)相關(guān)的操作。作為一個(gè)初學(xué)者來(lái)說(shuō),這一點(diǎn)是必須要掌握。下面就來(lái)具體分析一下PHP獲取字段屬性的技巧。#t#

字段除了有字段名、數(shù)據(jù)類型、長(zhǎng)度外,還有一些其他的屬性,比如是否為主鍵、是否為外鍵、是否允許為空等。PHP獲取字段屬性可通過(guò)mysql_field_flags()函數(shù),該函數(shù)的語(yǔ)法格式如下:
string mysql_field_flags ( resource $result, int $field_offset )
在上述語(yǔ)法中涉及到的參數(shù)說(shuō)明如下:
l result:mysql_query()函數(shù)執(zhí)行后返回的結(jié)果集。
l field_offset:字段的偏移量,起始值為零。
使用mysql_field_flags()函數(shù)的PHP獲取字段屬性示例代碼如下:
- < ?php
- $connection=mysql_connect("localhost",
"root","root") or die("連接服務(wù)器失敗");- mysql_select_db("sunyang",$connection)
or die("選擇數(shù)據(jù)庫(kù)失敗");- $query="select * from employee";
- $result=mysql_query($query) or die
("查詢數(shù)據(jù)失敗"); //執(zhí)行查詢- echo mysql_field_flags($result, 0);
//***個(gè)字段的屬性- echo "
";- echo mysql_field_flags($result, 1);
//第二個(gè)字段的屬性- echo "
";- echo mysql_field_flags($result, 2);
//第三個(gè)字段的屬性- mysql_free_result($result);
- mysql_close();
- ?>
以上就是我們?yōu)榇蠹曳窒淼腜HP獲取字段屬性的相關(guān)技巧。
文章標(biāo)題:講解PHP獲取字段屬性技巧
URL地址:http://www.5511xx.com/article/djdhidh.html


咨詢
建站咨詢
