Hongmu Notes
Home Language Notes PHP: Retrieving field comments from a database table
Language Notes PHP

PHP: Retrieving field comments from a database table

PHP: Retrieving field comments from a database table

You can use the combination of PHP and MySQLi to retrieve the comment information for fields in a database table.

Use the `fetch_fields()` function from the `mysqli_result` class to retrieve an array of all field objects; then iterate over each field object, use the `real_escape_string()` function from MySQLi to escape the field names, and combine these escaped names into an SQL query statement; finally, execute the query statement to retrieve the field comment information.

Here is sample code:

$conn = new mysqli('localhost', '用户名', '密码', '数据库名');
if ($conn->connect_error) {
    die('Connect Error (' . $conn->connect_errno . ') '
            . $conn->connect_error);
}

$res = $conn->query('SELECT * FROM 表名');
$fields = $res->fetch_fields();

foreach ($fields as $field) {
    $result = $conn->query('SELECT column_comment FROM information_schema.columns WHERE table_name = \'' . $res->table_name . '\' and column_name = \'' . $field->name . '\';');
    $row = $result->fetch_assoc();
    echo '字段 ' . $field->name . ' 注释:' . $row['column_comment'] . '<br>';
}

$conn->close();
微信赞赏

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

Responsive Water Supply Pipeline Valve Website Template 0678

Responsive Water Supply Pipeline Valve Website Template 0678 Practical Collection Yiyou template

An eYouCMS responsive website template designed for the water supply pipeline and valve industry. Its professional industrial design style is ideal for showcasing pipeline products, valve series, technical specifications, and engineering applications. This template helps pipeline and valve manufacturers showcase their products online and attract construction and industrial clients. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS...
👁 29
(Adaptive Mobile Version) Bilingual (Chinese/English) Foreign Trade Website Template; Speaker and Audio System Website Template – 1104

(Adaptive Mobile Version) Bilingual (Chinese/English) Foreign Trade Website Template; Speaker and Audio System Website Template – 1104 Practical Collection pbootcms Template

A bilingual (Chinese/English) PbootCMS website template designed for export-oriented businesses and speaker audio systems, compatible with both PC and WAP devices. Its modern, international design makes it ideal for showcasing products and brands to global audio system manufacturers. The multilingual support facilitates effective brand promotion across international markets. Template Preview | Installation Instructions | Website Admin Panel: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn...
👁 46
(Adaptive mobile version) Simplified/Traditional Chinese bilingual PBootCMS template for hardware equipment manufacturers' corporate websites; Downloadable source code for general mining and ore processing equipment websites – 0380

(Adaptive mobile version) Simplified/Traditional Chinese bilingual PBootCMS template for hardware equipment manufacturers' corporate websites; Downloadable source code for general mining and ore processing equipment websites – 0380 Practical Collection pbootcms Template

An adaptive, bilingual (Simplified/Traditional Chinese) mobile-friendly PbootCMS template designed for mechanical hardware equipment manufacturers. Its professional and practical design makes it ideal for showcasing mining equipment and general mechanical products. This template helps heavy machinery enterprises enhance their brand visibility in both domestic and overseas Chinese markets. Template Demo | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: Pb...
👁 34
Fully hydraulic dual drive excavator and roller website template 0679

Fully hydraulic dual drive excavator and roller website template 0679 Practical Collection Yiyou template

This set of eyoucms templates is suitable for the fully hydraulic dual-drive excavator and road roller industries. The design style is yellow and professional. It can display excavator and road roller products, engineering machinery and equipment, technical parameters and construction cases. It helps construction machinery companies display their products online and attract infrastructure and mining customers. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Yiyou CMS security...
👁 56
(Adaptive Mobile Version) Packaging Machine Website Template – Labeling Machine Website Source Code Download – 1105

(Adaptive Mobile Version) Packaging Machine Website Template – Labeling Machine Website Source Code Download – 1105 Practical Collection pbootcms Template

A packaging machine and labeling machine website template based on PbootCMS, compatible with both PC and WAP devices. The professional and practical design is ideal for showcasing packaging machinery, labeling machine products, and industrial applications. It enables packaging equipment manufacturers to display their products online and attract customers from the food and pharmaceutical industries. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn (Related resources...)
👁 51