PHP 访问MySQL扩展 mysqli 内容

版权声明:请多多指教 https://blog.csdn.net/arctic_fox_cn/article/details/82531943

PHP学习

一、数据库扩展mysqli

学习来源: php官网手册 这是一个链接

mysqli::$connect_errno 
#int $mysqli->connect_errno;
#存储为最后一次连接数据库的错误代码,一个int类型数值;
mysqli::$connect_error;
#string $Mysqli->connect_error;
#存储为最后一次连接数据库的错误消息,一个string类型值;
mysqli::$host_info;
#string $mysqli->host_info;
#表示服务器主机名和连接类型
bool mysqli::select_db(string $dbname);
#选择数据库,返回bool 值
mysqli::$client_info;
#string $mysqli->client_info; 返回字符串类型,关于客户端的信息
mysqli::get_client_info(void);
#string mysqli::get_client_info(void); 与$mysqli->client_info一样
mysqli::$client_version;
#int $mysqli->client_version;
#返回客户端版本号;
mixed mysqli::query(string $query,[,int  $resultmode = MYSQLI_STORE_RESULT ]);
#mixed 表示可以返回多种类型  $resultmode 默认为MYSQLI_STORE_RESULT;
#array mysqli_result::fetch_assoc(void);
#返回一个数组,里面存储的是结果中的第一个元素,如果再次使用fetch_assoc(),将会返回结果的第二个元素。
#如果将结果中的数据读取完,如果再次读取便会为空。
#比如 使用mysqli_result::fetc_row 读取完$result 的数据,之后再使用mysqli_result:: fetch_assoc 会发现没有任何有效值。

result对象内具体内容

mysqli_result {
/* 属性 */
int $current_field ; 
int $field_count;
array $lengths;
int $num_rows;
/* 方法 */
int mysqli_field_tell ( mysqli_result $result )
bool data_seek ( int $offset )
mixed fetch_all ([ int $resulttype = MYSQLI_NUM ] )
mixed fetch_array ([ int $resulttype = MYSQLI_BOTH ] )
array fetch_assoc ( void )
object fetch_field_direct ( int $fieldnr )
object fetch_field ( void )
array fetch_fields ( void )
object fetch_object ([ string $class_name = "stdClass" [, array $params ]] )
mixed fetch_row ( void )
int mysqli_num_fields ( mysqli_result $result )
bool field_seek ( int $fieldnr )
void free ( void )
array mysqli_fetch_lengths ( mysqli_result $result )
int mysqli_num_rows ( mysqli_result $result )
}
  • mysqli_result :: fetch_field

    array mysqli_result::fetch_field(void)
    //返回结果集中的字段信息,多次调用可以查看结果集全部信息
Property Description
name 列名
table 表名
db 数据库名
decimals The number of decimals used (for integer fields)
……………. ……………………..

PHP官网 详解 这是一个链接

  • mysqli_result::$num_rows

    
    #返回结果集中的行数
    
    echo "rows_count:".$result->num_rows;
    
    #这里的对象是$result
    
  • mysqli_result::fetch_assoc

    
    #获取结果行作为  [关联,关联,关联]  数组 ["name"]["age"] ["job"]
    
    for($i=0;$i<$result->num_rows;$i++)
      {
        $row=$result->fetch_assoc();
        print_r($row);
        echo $row["id"];
        echo "<br/>";
      }
      echo "<br/>".gettype($row);
      $result->close();
  • mysqli_result::fetch_row

    
    #获取结果行作为枚举数组   [0][1][2][3]
    
    获取结果行作为  [关联,关联,关联]  数组 ["name"]["age"] ["job"]
    for($i=0;$i<$result->num_rows;$i++)
      {
        $row=$result->fetch_assoc();
        print_r($row);
        echo $row[0];
        echo "<br/>";
      }
      echo "<br/>".gettype($row);
      $result->close();
  • mysqli_result::free

  • mysqli_result::close

    $result->close;
    $result->free;
    $result->free_result;
    
    #释放结果集所占用的内存,也就是说在使用上面这些语句之后,就不能再访问result内容,需要再次访问
    

    Date:Sat Sep 8 18:13:42 CST 2018

猜你喜欢

转载自blog.csdn.net/arctic_fox_cn/article/details/82531943