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();