PPHP mysqli_free_result() 函数 从结果集中取得行,然后释放结果内存: mysqli_fetch_array() <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); 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)) { // 一行行获取 while ($row=mysqli_fetch_row($result)) { printf ("%s : %s",$row[0],$row[1]); echo "<br>"; } // 释放结果集 mysqli_free_result($result); } mysqli_close($con); ?> 定义和用法 mysqli_free_result() 函数释放结果内存。 语法 mysqli_free_result( _result_ ) _;_ 参数 描述 _result_ 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 技术细节 返回值: 没有返回值。 PHP 版本: 5+
阅读全文 ↗ PPHP mysqli_field_tell() 函数 取得所有字段的字段信息,然后通过 mysqli_field_tell() 取得当前字段并输出字段名称、表格和最大长度: <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); 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)) { //获取所有字段信息 while ($fieldinfo=mysqli_fetch_field($result)) { // 获取当前字段信息 $currentfield=mysqli_field_tell($result); printf("列 %d", $currentfield); echo "<br>"; printf("字段名: %s", $fieldinfo->name); echo "<br>"; printf("表名: %s", $fieldinfo->table); echo "<br>"; } // 释放结果集 mysqli_free_result($result); } mysqli_close($con); ?> 定义和用法 mysqli_field_tell() 函数返回字段指针的位置。 语法 mysqli_field_tell( _result_ ) _;_ 参数 描述 _result_ 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 技术细节 返回值: 返回字段指针的当前偏移量。 PHP 版本: 5+
阅读全文 ↗ PPHP mysqli_field_seek() 函数 设置结果集中第一个字段(列)的字段指针,然后通过 mysqli_fetch_field() 获取字段信息并输出字段名称、表格和最大长度: <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); 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)) { // 获取第一列 ("name") 的字段信息 mysqli_field_seek($result,0); $fieldinfo=mysqli_fetch_field($result); printf("字段名: %s",$fieldinfo->name); echo "<br>"; printf("表名: %s",$fieldinfo->table); echo "<br>"; printf("字段长度: %d",$fieldinfo->max_length); // 释放结果集 mysqli_free_result($result); } mysqli_close($con); ?> 定义和用法 mysqli_field_seek() 函数把字段指针设置为指定字段的偏移量。 语法 mysqli_field_seek( _result,fieldnr_ ) _;_ 参数 描述 _result_ 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 _fieldnr_ 必需。规定字段号。必须介于 0 和 字段数-1 之间。 技术细节 返回值: 如果成功则返回 TRUE,如果失败则返回 FALSE。 PHP 版本: 5+
阅读全文 ↗ PPHP mysqli_field_count() 函数 假设我们有一个 "websites" 表,其中有 5 个字段 20 行记录。返回最近查询的列数: <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); if (mysqli_connect_errno($con)) { echo "连接 MySQL 失败: " . mysqli_connect_error(); } mysqli_query($con,"SELECT * FROM websites"); // 获取列数 echo mysqli_field_count($con); mysqli_close($con); ?> 定义和用法 mysqli_field_count() 函数返回最近查询的列数。 语法 mysqli_field_count( _connection_ ) _;_ 参数 描述 _connection_ 必需。规定要使用的 MySQL 连接。 技术细节 返回值: 返回一个表示结果集中列数的整数。 PHP 版本: 5+
阅读全文 ↗ PPHP mysqli_fetch_row() 函数 从结果集中取得行: <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); 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)) { while ($obj=mysqli_fetch_object($result)) { printf("%s : %s",$obj->name,$obj->url); echo "<br>"; } // 释放结果集合 mysqli_free_result($result); } mysqli_close($con); ?> 定义和用法 mysqli_fetch_row() 函数从结果集中取得一行,并作为枚举数组返回。 语法 mysqli_fetch_row( _result_ ) _;_ 参数 描述 _result_ 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 技术细节 返回值: 返回一个与所取得行相对应的字符串数组。如果在结果集中没有更多的行则返回 NULL。 PHP 版本: 5+
阅读全文 ↗ PPHP mysqli_fetch_object() 函数 返回结果集中的当前行,然后输出每个字段的值: <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); 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)) { while ($obj=mysqli_fetch_object($result)) { printf("%s : %s",$obj->name,$obj->url); echo "<br>"; } // 释放结果集合 mysqli_free_result($result); } mysqli_close($con); ?> 定义和用法 mysqli_fetch_object() 函数从结果集中取得当前行,并作为对象返回。 注释: 该函数返回的字段名是区分大小写的。 语法 mysqli_fetch_object( _result,classname,params_ ) _;_ 参数 描述 _result_ 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 _classname_ 可选。规定要实例化的类名称,设置属性并返回。 _params_ 可选。规定一个传给 _classname_ 对象构造器的参数数组。 技术细节 返回值: 返回带有所取得行的字符串属性的对象。如果在结果集中没有更多的行则返回 NULL。 PHP 版本: 5+ 更新日志: 在 PHP 5.0.0 中新增了作为不同对象返回的功能。
阅读全文 ↗ PPHP mysqli_fetch_lengths() 函数 返回结果集中的字段长度: <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); 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+
阅读全文 ↗ PPHP mysqli_fetch_fields() 函数 返回结果集中代表字段(列)的对象的数组,然后输出每个字段名称、表格和最大长度: <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); 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)) { // 获取所有字段的信息 $fieldinfo=mysqli_fetch_fields($result); foreach ($fieldinfo as $val) { printf("字段名: %s",$val->name); echo "<br>"; printf("数据表: %s",$val->table); echo "<br>"; printf("最大长度: %d",$val->max_length); echo "<br>"; } // 释放结果集 mysqli_free_result($result); } mysqli_close($con); ?> 定义和用法 mysqli_fetch_fields() 函数返回结果集中代表字段(列)的对象的数组。 语法 mysqli_fetch_fields( _result_ ) _;_ 参数 描述 _result_ 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 技术细节 返回值: 返回包含字段定义信息的对象。如果没有可用信息则返回 FALSE。该对象有下列属性: * name - 列名 * orgname - 原始的列名(如果指定了别名) * table - 表名 * orgtable - 原始的表名(如果指定了别名) * max_length - 字段的最大宽度 * length - 在表定义中规定的字段
阅读全文 ↗ PPHP mysqli_fetch_field() 函数 返回结果集中下一字段(列),然后输出每个字段名称、表格和最大长度: <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); 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)) { // 获取所有列的字段信息 while ($fieldinfo = mysqli_fetch_field($result)) { printf("字段名: %s\n", $fieldinfo->name); echo "<br>"; printf("数据表: %s\n", $fieldinfo->table); echo "<br>"; printf("最大长度: %d\n", $fieldinfo->max_length); echo "<br>"; } // 释放结果集 mysqli_free_result($result); } mysqli_close($con); ?> 定义和用法 mysqli_fetch_field() 函数从结果集中取得下一字段(列),并作为对象返回。 语法 mysqli_fetch_field( result ) ; 参数 描述 _result_ 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 技术细节 返回值: 返回包含字段定义信息的对象。如果没有可用信息则返回 FALSE。该对象有下列属性: * name - 列名 * orgname - 原始的列名(如果指定了别名) * table - 表名 * orgtable - 原始的表名(如果指定了别名) * def - 保留作为默认值,当前总是为 "" * db - 数据库(在 PHP 5.3.6
阅读全文 ↗ PPHP mysqli_fetch_field_direct() 函数 返回结果集中某个单一字段(列)的 meta-data,并输出字段名称、表格和最大长度: <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); 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)) { // 获取字段 "name" 的信息 $fieldinfo=mysqli_fetch_field_direct($result,1); printf("字段名: %s",$fieldinfo->name); echo "<br>"; printf("数据表: %s",$fieldinfo->table); echo "<br>"; printf("最大长度: %d",$fieldinfo->max_length); // 释放结果集 mysqli_free_result($result); } mysqli_close($con); ?> 定义和用法 mysqli_fetch_field_direct() 函数从结果集中取得某个单一字段(列)的 meta-data,并作为对象返回。 语法 mysqli_fetch_field_direct( result,fieldnr ) ; 参数 描述 _result_ 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 _fieldnr_ 必需。规定字段号。必须介于 0 和 字段数-1 之间。 技术细节 返回值: 返回包含字段定义信息的对象。如果没有可用信息则返回 FALSE。该对象有下列属性: * name - 列名 * orgname - 原始的列名(如果指定了别名) * table - 表名 * orgt
阅读全文 ↗ PPHP mysqli_fetch_assoc() 函数 从结果集中取得一行作为关联数组: mysqli_fetch_assoc() <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); if (mysqli_connect_errno($con)) { echo "连接 MySQL 失败: " . mysqli_connect_error(); } $sql="SELECT name,url FROM websites ORDER BY alexa"; $result=mysqli_query($con,$sql); // 关联数组 $row=mysqli_fetch_assoc($result); printf ("%s : %s)",$row["name"],$row["url"]); // 释放结果集 mysqli_free_result($result); mysqli_close($con); ?> 定义和用法 mysqli_fetch_assoc() 函数从结果集中取得一行作为关联数组。 注释: 该函数返回的字段名是区分大小写的。 语法 mysqli_fetch_assoc( _result_ ) _;_ 参数 描述 _result_ 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 技术细节 返回值: 返回代表读取行的关联数组。如果结果集中没有更多的行则返回 NULL。 PHP 版本: 5+
阅读全文 ↗ PPHP mysqli_fetch_array() 函数 从结果集中取得一行作为数字数组或关联数组: mysqli_fetch_array() <?php // 假定数据库用户名:root,密码:123456,数据库:codingdict $con=mysqli_connect("localhost","root","123456","codingdict"); if (mysqli_connect_errno($con)) { echo "连接 MySQL 失败: " . mysqli_connect_error(); } $sql="SELECT name,url FROM websites ORDER BY alexa"; $result=mysqli_query($con,$sql); // 数字数组 $row=mysqli_fetch_array($result,MYSQLI_NUM); printf ("%s : %s",$row[0],$row[1]); // 关联数组 $row=mysqli_fetch_array($result,MYSQLI_ASSOC); printf ("%s : %s",$row["name"],$row["url"]); // 释放结果集 mysqli_free_result($result); mysqli_close($con); ?> 定义和用法 mysqli_fetch_array() 函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有。 注释: 该函数返回的字段名是区分大小写的。 语法 mysqli_fetch_array( _result,resulttype_ ) _;_ 参数 描述 _result_ 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 _resulttype_ 可选。规定应该产生哪种类型的数组。可以是以下值中的一个: * MYSQLI_ASSOC * MYSQLI_NUM * MYSQLI_BOTH 技术细节 返回值: 返回与读取行匹配的字符串数组。如果结果集中没有更多的行则返回 NULL。 PHP 版本: 5+
阅读全文 ↗