CakeFest 2024: The Official CakePHP Conference

mysql_fetch_lengths

(PHP 4, PHP 5)

mysql_fetch_lengths取得结果集中每个输出的长度

警告

本扩展自 PHP 5.5.0 起已废弃,并在自 PHP 7.0.0 开始被移除。应使用 MySQLiPDO_MySQL 扩展来替换之。参见 MySQL:选择 API 指南来获取更多信息。用以替代本函数的有:

说明

mysql_fetch_lengths(resource $result): array|false

返回数组,对应 MySQL 查询中获取的最后一行的每个字段的长度。

mysql_fetch_lengths() 将上一次 mysql_fetch_row()mysql_fetch_assoc()mysql_fetch_array()mysql_fetch_object() 所返回的最后一行的每个字段的长度储存到一个数组中,偏移量从 0 开始。

参数

result

resource 型的结果集。此结果集来自对 mysql_query() 的调用。

返回值

An array of lengths on success 或者在失败时返回 false.

示例

示例 #1 mysql_fetch_lengths() 示例

<?php
$result
= mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!
$result) {
echo
'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_assoc($result);
$lengths = mysql_fetch_lengths($result);

print_r($row);
print_r($lengths);
?>

以上示例的输出类似于:

Array
(
    [id] => 42
    [email] => user@example.com
)
Array
(
    [0] => 2
    [1] => 16
)

参见

add a note

User Contributed Notes 1 note

up
-8
Bavo Janss
14 years ago
In case of UTF8 fields mysql_field_len() will return 3 times the maximum length (e.g. 30 for a VARCHAR(10) field)) for mysql_field_len() returns the byte length of the field not the defined size.
To Top