PHP mysqli_fetch_lengths() 函数

PHP 教程 · 2019-01-27 21:43:25

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

<?php 
// 假定数据库用户名:root,密码:123456,数据库:CODERCTO 
$con=mysqli_connect("localhost","root","123456","CODERCTO"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "连接 MySQL 失败: " . mysqli_connect_error(); 
} 

$sql="SELECT name,url FROM websites ORDER BY alexa";


if ($result=mysqli_query($con,$sql))
{
    $row=mysqli_fetch_row($result);
    
    // 显示字段长度
    foreach (mysqli_fetch_lengths($result) as $i=>$val)
    {
        printf("字段 %2d 长度为: %2d",$i+1,$val);
        echo "<br>";
    }
    
    // 释放结果集
    mysqli_free_result($result);
}

mysqli_close($con);
?>

定义和用法

mysqli_fetch_lengths() 函数返回结果集中的字段长度。

语法

mysqli_fetch_lengths(result);

参数 描述
result 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。

技术细节

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

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Foundation Web Standards

Foundation Web Standards

Jonathan Lane、Steve Smith / Friends of ED / 21st July 2008 / $34.99

Foundation Web Standards explores the process of constructing a web site from start to finish. There is more to the process than just knowing HTML! Designers and developers must follow a proper proces......一起来看看 《Foundation Web Standards》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具