返回结果集中当前行的字段长度:
<?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)
Parameter | Description |
---|---|
result | Required. Specifies a result set identifier returned by mysqli_query(), mysqli_store_result() or 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);
?>
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!