Hongmu Notes
Home Language Notes PHP: Retrieving structural attributes of database table fields
Language Notes PHP

PHP: Retrieving structural attributes of database table fields

PHP: Retrieving structural attributes of database table fields

You can use the `mysql_fetch_field()` function in PHP to retrieve the structural attributes of a field in a database table.

Example usage:

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons");

while ($fieldinfo = mysql_fetch_field($result))
{
    echo $fieldinfo->name;
    echo $fieldinfo->max_length;
    echo $fieldinfo->type;
}

mysql_close($con);

This code can be retrieved. Persons The names, maximum lengths, and data types of all fields in the table.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 189
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

(Adaptive mobile version) SEO blog website template – News and information website source code download – 1106

(Adaptive mobile version) SEO blog website template – News and information website source code download – 1106 Practical Collection pbootcms Template

An SEO-friendly blog and news website template built with PbootCMS, compatible with both PC and WAP devices. Its clean and informative design makes it ideal for SEO bloggers to share optimization techniques, industry trends, and case studies. This template helps SEO professionals build their personal brand and expand their knowledge-based influence online. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5...
👁 54
Responsive Hardware Accessories Mechanical & Electrical Website Template 0681

Responsive Hardware Accessories Mechanical & Electrical Website Template 0681 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the hardware and electromechanical industries. Its professional and precise design style enables effective presentation of hardware products, electromechanical equipment, technical specifications, and industrial applications. It helps hardware and electromechanical enterprises showcase their products online and attract industrial customers. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 31
(Adaptive mobile version) Simplified/Traditional Chinese Green HTML5 Responsive Eco-Friendly Equipment pbootCMS Template – Download Website Source Code for an Eco-Tech Company – 0382

(Adaptive mobile version) Simplified/Traditional Chinese Green HTML5 Responsive Eco-Friendly Equipment pbootCMS Template – Download Website Source Code for an Eco-Tech Company – 0382 Practical Collection pbootcms Template

An adaptive, mobile-friendly, simple-to-use, Chinese-English bilingual, responsive, and eco-friendly PbootCMS template. Its fresh and sustainable design makes it ideal for environmental technology companies to showcase their products and technical solutions. Multi-language support enables businesses to promote green technologies across both sides of the Taiwan Strait and in Chinese-speaking markets. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: Pboot...
👁 39
(PC + WAP) Shade Fabric (Color Stripe Fabric) Website Template – Download Website Source Code for Rainproof and Sunshade Canvas Canopy – 1107

(PC + WAP) Shade Fabric (Color Stripe Fabric) Website Template – Download Website Source Code for Rainproof and Sunshade Canvas Canopy – 1107 Practical Collection pbootcms Template

A PbootCMS website template combining sunshade fabric with rain-and sun-protection篷 fabric, compatible with both PC and WAP devices. The design is practical and professional, ideal for showcasing sunshade fabric products,篷 fabrics, and industrial applications. It helps篷 fabric companies showcase their products online and attract construction and outdoor industry clients. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn...
👁 57