PHP mysql_fetch_lengths() 函數
定義和用法
mysql_fetch_lengths() 函數取得一行中每個字段的內容的長度。
行是由這些函數返回的:mysql_fetch_array()、mysql_fetch_assoc()、mysql_fetch_object() 或 mysql_fetch_row()。
若成功,則該函數返回一個數字數組,若出錯或沒有其他的行,則返回 false。
語法
mysql_fetch_lengths(data)
參數 | 描述 |
---|---|
data | 必需。要使用的數據指針。該數據指針是從 mysql_query() 返回的結果。 |
實例
<?php $con = mysql_connect("localhost", "peter", "abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db("test_db",$con); $sql = "SELECT * from Person WHERE Lastname='Refsnes'"; $result = mysql_query($sql,$con); print_r(mysql_fetch_row($result)); print_r(mysql_fetch_lengths($result)); mysql_close($con); ?>
輸出:
Array ( [0] => Adams [1] => John [2] => London ) Array ( [0] => 5 [1] => 4 [2] => 6 )