Php/func mysqli fetch lengths

来自菜鸟教程
跳转至:导航、​搜索

PHP长度/ mysqli_fetch_lengths()函数

MySQL PHP MySQLi参考

示例-面向对象的样式

返回结果集中当前行字段的长度:

<?php

$mysqli = new mysqli("localhost","my_user","my_password","my_db");


if ($mysqli -> connect_errno) {

  echo "Failed to connect to MySQL: " . 
  $mysqli -> connect_error;
  
  exit();

  }

$sql = "SELECT * FROM Persons ORDER BY Lastname";


if ($result = $mysqli -> query($sql)) {

    $row = 
  $result -> fetch_row();
  // Display field lengths
  foreach ($result 
  -> lengths as $i => $val) {
    printf("Field %2d has length: %2d\n", $i + 1, $val);
  }

    $result 
  -> free_result();
}


$mysqli -> close();
?>



在底部查看程序样式的示例。

定义和用法

lengths / mysqli_fetch_lengths()函数返回结果集中当前行字段的长度。

句法

面向对象的样式:

$mysqli_result -> lengths

程序风格:

mysqli_fetch_lengths(result)

参数值

参数 描述
result 需要。指定mysqli_query(),mysqli_store_result()或mysqli_use_result()返回的结果集标识符

技术细节

返回值: 返回表示每个字段(列)大小的整数数组。如果发生错误则为FALSE
PHP版本: 5+

示例-程序风格

返回结果集中当前行字段的长度:

<?php

$con = mysqli_connect("localhost","my_user","my_password","my_db");


if (mysqli_connect_errno()) {

  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  
  exit();

  }

$sql = "SELECT * FROM Persons ORDER BY Lastname";


if ($result = mysqli_query($con, $sql)) {
  $row = mysqli_fetch_row($result);

    // Display field lengths
  foreach (mysqli_fetch_lengths($result) as $i => $val) {
    printf("Field %2d has length: %2d\n", $i+1, $val);
  }


  mysqli_free_result($result);
}


mysqli_close($con);

?>



MySQL PHP MySQLi参考