10bet网址
MySQL PHP API
下载本手册

MySQL PHP API/.../ mysqli_fetch_lengths mysqli_result:: $长度

3.10.14mysqli_result:: $长度mysqli_fetch_lengths

PHP文档组版权所有。10bet官方网站

  • mysqli_result:: $长度

    mysqli_fetch_lengths

    返回结果集中当前行的列的长度

描述

面向对象的风格

假| |空数组mysqli_result - >长度

程序上的风格

数组|假mysqli_fetch_lengthsmysqli_result结果);

mysqli_fetch_lengths函数返回一个数组,该数组包含结果集中当前行的每一列的长度。

参数

结果

仅限过程式样式:返回的结果集标识符mysqli_querymysqli_store_resultmysqli_use_result

返回值

表示每列大小的整数数组(不包括任何终止空字符)。如果发生错误。

mysqli_fetch_lengths仅对结果集的当前行有效。它返回如果你在调用mysqli_fetch_row/array/object之前或者在检索结果中的所有行之后调用它。

例子

例3.121面向对象样式

<?PHP $mysqli = new mysqli("localhost", "my_user", "my_password", "world");/*检查连接*/ if (mysqli_connect_errno()) {printf("Connect failed: %s\n", mysqli_connect_error());退出();} $query = "SELECT * from Country ORDER BY Code LIMIT 1";If ($result = $mysqli->query($query)) {$row = $result->fetch_row();/*显示列长度*/ foreach ($result->长度为$i => $val) {printf("字段%2d有长度%2d\n", $i+1, $val);}结果- > close ();} /*关闭连接*/ $mysqli->close();?>

例3.122过程式风格

<?PHP $link = mysqli_connect("localhost", "my_user", "my_password", "world");/*检查连接*/ if (mysqli_connect_errno()) {printf("Connect failed: %s\n", mysqli_connect_error());退出();} $query = "SELECT * from Country ORDER BY Code LIMIT 1";If ($result = mysqli_query($link, $query)) {$row = mysqli_fetch_row($result);/*显示列长度*/ foreach (mysqli_fetch_length ($result) as $i => $val) {printf("字段%2d有长度%2d\n", $i+1, $val);} mysqli_free_result(结果);} /*关闭连接*/ mysqli_close($link);?>

上面的例子将输出:

字段1的长度为3字段2的长度为5字段3的长度为13字段4的长度为9字段5的长度为6字段6的长度为1字段7的长度为6字段9的长度为6字段10的长度为6字段11的长度为5字段12的长度为44字段13的长度为7字段14的长度为3字段15的长度为2