CakeFest 2024: The Official CakePHP Conference

mysql_field_len

(PHP 4, PHP 5)

mysql_field_len返回指定字段的长度

警告

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

说明

mysql_field_len(resource $result, int $field_offset): int|false

mysql_field_len() 返回指定字段的长度。

参数

result

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

field_offset

数值型字段偏移量。 field_offset0 开始。如果 field_offset 不存在,则会发出一个 E_WARNING 级别的错误

返回值

The length of the specified field index on success 或者在失败时返回 false.

示例

示例 #1 mysql_field_len() 示例

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

// Will get the length of the id field as specified in the database
// schema.
$length = mysql_field_len($result, 0);
echo
$length;
?>

注释

注意:

为了向下兼容,可以使用下列已废弃的别名: mysql_fieldlen()

参见

add a note

User Contributed Notes 2 notes

up
1
rvwoens at gmail dot com
12 years ago
Note that for some reason the length of fields is 3 times the actual value if you are using UTF8 encoding.. So a varchar(10) field returns 30 here. This renders this function almost useless.
up
-9
adam_nospam_hunger at yahoo dot com
20 years ago
For a mysql type DECIMAL(8,4), the length is returned as 10 (M+2 as per documentation).
To Top