mysql_fetch_field() function
အသံုးျပဳပံု နဲ႔ သတ္မွတ္ခ်က္
mysql_fetch_field() function ကေတာ႔ recordset တစ္ခုထဲ႔က Field တစ္ခုရဲ႕ information မွာပါ၀င္တဲ႔ object ကို return ျပန္ေပးပါတယ္
ဒီ function က mysql_query() function ကေန data ကိုရရွိမွာပါ ျပီးေတာ႔ မွန္တယ္ဆိုရင္ object ကို return ျပန္ေပးျပီးေတာ႔ မွားတယ္ဆုိရင္ data failure ျဖစ္သြားမွာပါ
ရလာမယ္႔ return values ေတြကေတာ႔
name - Field name
table - The table the field belongs to
def - Default value for the field
max_length - Maximum field length
not_null - 1 if the field cannot be NULL
primary_key - 1 if the field is a primary key
unique_key - 1 if the field is a unique key
multiple_key - 1 if the field is a non-unique key
numeric - 1 if the field is numeric
blob - 1 if the field is a BLOB
type - Field type
unsigned - 1 if the field is unsigned
zerofill - 1 if the field is zero-filled
Syntax
mysql_fetch_field(data,field_offset)
data = မရွိမျဖစ္ထည္႔ေပးရမွာပါ။ဘယ္ data ကိုသံုးရမယ္ဆိုတာ ဆိုလိုပါတယ္၊ data ဆိုတာ mysql_query() function ကေနရရွိမွာပါ
field_offset = မထည္႔လည္းရပါတယ္၊ ဘယ္ field ကေန စမယ္ဆိုတာကိုသတ္မွတ္တာပါ 0 ဆိုတာ ပထမဆံုး field ကို ေျပာပါတယ္
အကယ္ရွ္ parameter မထည္႔ဘူးဆိုရင္ ေနာက္ထပ္ field တစ္ခုကို ထုတ္ယူမွာျဖစ္ပါတယ္
ဥပမာ
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die("Could not connect to : " . mysql_error());
}
$db=mysql_select_db("mydb","$con");
$sql="SELECT * FROM table ";
$result= mysql_query($sql,$con);
while($property = mysql_fetch_field($result))
{
echo "Field name : " .$property->name . "<br/>";
echo "Table name : " .$property->table . "<br/>";
echo "Default value : " . $property->def . "<br/>";
echo "Max Length : " . $property->max_length . "<br/>";
echo "Not NULL : " . $property->not_null . "<br/>";
echo "Primary Key : " .$property->primary_key . "<br/>";
echo "Unique Key : " .$property->unique_key ."<br/>";
echo "Multiple Key : " .$property->multiple_key. "<br/>";
echo "Numeric Field : " .$property->numeric ." <br/>";
echo "BLOB:" . $property->blob ."<br/>";
echo "Field Type : " . $property->type ."<br/>";
echo "Unsigned : " . $property->unsigned ."<br/>";
echo "Zero-filled : " .$property->zerofill ."<br/><br/>";
}
mysql_close($con);
?>
The Output is
Field name: Name
Table name: table
Default value:
Max length: 7
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 0
BLOB: 0
Field Type: string
Unsigned: 0
Zero-filled: 0
Field name: Address
Table name: table
Default value:
Max length: 9
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 0
BLOB: 0
Field Type: string
Unsigned: 0
Zero-filled: 0
Field name: Age
Table name: table
Default value:
Max length: 2
Not NULL: 0
Primary Key: 0
Unique Key: 0
Mutliple Key: 0
Numeric Field: 1
BLOB: 0
Field Type: int
Unsigned: 0
Zero-filled: 0
အဆင္ေျပပါေစဗ်ာ
No comments:
Post a Comment
Thanks for your comments
Welcome from cyberoot