mysql_fetch_lengths
Gets the length of the contents of each field in the result set.
Function name: mysql_fetch_lengths()
Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7
Usage: the mysql_fetch_lengths() function returns the length of each field in the current row in the result set. This function can only be used for MySQL query results.
Syntax: array mysql_fetch_lengths ( resource $result )
parameter:
Return value: Returns an array containing the lengths of each field in the current row. If there are no more rows, false is returned.
Example:
<?php // 连接数据库$link = mysql_connect('localhost', 'username', 'password'); if (!$link) { die('无法连接到数据库: ' . mysql_error()); } // 选择数据库$db_selected = mysql_select_db('database_name', $link); if (!$db_selected) { die ('无法选择数据库: ' . mysql_error()); } // 执行查询$result = mysql_query('SELECT * FROM table_name', $link); if (!$result) { die('查询执行失败: ' . mysql_error()); } // 获取结果集中当前行的各个字段的长度while ($row = mysql_fetch_lengths($result)) { foreach ($row as $length) { echo "字段长度: " . $length . "<br>"; } } // 释放结果集mysql_free_result($result); // 关闭数据库连接mysql_close($link); ?>
Notes: