دالة PHP mysqli fetch_fields ()
مثال - أسلوب كائن المنحى
قم بإرجاع مصفوفة من الكائنات التي تمثل الحقول في مجموعة النتائج ، ثم اطبع اسم كل حقل وجدول وأقصى طول:
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " .
$mysqli -> connect_error;
exit();
}
$sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname";
if ($result = $mysqli -> query($sql)) {
// Get field information for all fields
$fieldinfo =
$result -> fetch_fields();
foreach ($fieldinfo as
$val) {
printf("Name: %s\n", $val -> name);
printf("Table: %s\n", $val -> table);
printf("Max. Len: %d\n", $val -> max_length);
}
$result
-> free_result();
}
$mysqli -> close();
?>
انظر إلى مثال على الأسلوب الإجرائي في الأسفل.
التعريف والاستخدام
ترجع الدالة fetch_fields () / mysqli_fetch_fields () مصفوفة من الكائنات التي تمثل الحقول في مجموعة النتائج.
بناء الجملة
النمط الموجه للكائن:
$mysqli_result -> fetch_fields()
الأسلوب الإجرائي:
mysqli_fetch_fields(result)
قيمه المعامل
Parameter | Description |
---|---|
result | Required. Specifies a result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result() |
تفاصيل تقنية
قيمة الإرجاع: | تُرجع مصفوفة كائنات تحتوي على معلومات تعريف الحقل. خطأ في حالة عدم توفر معلومات. الكائنات لها الخصائص التالية:
|
---|---|
إصدار PHP: | 5+ |
مثال - أسلوب إجرائي
قم بإرجاع مصفوفة من الكائنات التي تمثل الحقول في مجموعة النتائج ، ثم اطبع اسم كل حقل وجدول وأقصى طول:
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname";
if ($result = mysqli_query($con , $sql)) {
// Get field information for all fields
$fieldinfo = mysqli_fetch_fields($result);
foreach ($fieldinfo as $val) {
printf("Name: %s\n", $val->name);
printf("Table: %s\n", $val->table);
printf("Max. Len: %d\n", $val->max_length);
}
mysqli_free_result($result);
}
mysqli_close($con);
?>
❮ PHP مرجع MySQLi