CakeFest 2024: The Official CakePHP Conference

mysql_fetch_lengths

(PHP 4, PHP 5)

mysql_fetch_lengths結果における各出力の長さを得る

警告

この拡張モジュールは PHP 5.5.0 で非推奨になり、PHP 7.0.0 で削除されました。 MySQLi あるいは PDO_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

評価された結果 リソース。この結果は、mysql_query() のコールにより得られたものです。

戻り値

成功した場合に長さの配列(array)を、 失敗した場合に 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