PHP mysqli_field_seek () function
Setting the result set the first field (column) field pointer, then () Gets field information through mysqli_fetch_field and output field names, and the maximum length of the table:
<?php // 假定数据库用户名:root,密码:123456,数据库:w3big $con=mysqli_connect("localhost","root","123456","w3big"); 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); ?>
Definition and Usage
mysqli_field_seek () function pointer is set to the field offset specified field.
grammar
mysqli_field_seek( result,fieldnr ) ;
参数 | 描述 |
---|---|
result | 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 |
fieldnr | 必需。规定字段号。必须介于 0 和 字段数-1 之间。 |
technical details
return value: | If successful it returns TRUE, on failure returns FALSE. |
---|---|
PHP version: | 5+ |
PHP MySQLi Reference Manual