Current Location: Home> Function Categories> mysql_fetch_lengths

mysql_fetch_lengths

Gets the length of the contents of each field in the result set.
Name:mysql_fetch_lengths
Category:Uncategorized
Programming Language:php
One-line Description:Returns the length of each field in the current row 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:

  • $result: Required. A MySQL query result resource.

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:

  • The mysql_fetch_lengths() function can only be used for MySQL query results and is not applicable to other database systems.
  • Since support for the mysql_* function has been removed in PHP 7, it is recommended to use the mysqli or PDO extension to connect to and operate the MySQL database.
Similar Functions
Popular Articles