面向对象函数库(笔记)

面向对象函数库(笔记)

面向对象函数库

Bool mysqli::close(void)

$mysqli=new mysqli();

$mysqli->close();

代码实现(面向对像)

<?php

header("Content-type:text/html;charset=utf-8");

$mysqli=newMySQLi("localhost:3306","root","myoa888","phpstudy");

if($mysqli->connect_error){

die("连接失败".$mysqli->connect_error);

}

mysql_query('set names gbk');

$sql="select * from user1";

$res=$mysqli->query($sql);

echo var_dump($sql);

while($row=$res->fetch_row()){

foreach($row as $key=>$val){

echo "==$val";

}

echo "<br/>";

}

$res->free();

$mysqli->close();

?>

代码实现(面向过程)

<?php

//header("Content-type:text/html;charset=utf-8");

$mysqli=newMySQLi("localhost:3306","root","myoa888","phpstudy");

if(!$mysqli){

die("连接失败".mysqli_connect_error($mysqli));

}

mysql_query('set names gbk');

$sql="select * from user1";

$res=mysqli_query($mysqli,$sql);

echo var_dump($sql);

while($row=mysqli_fetch_row($res)){

foreach($row as $key=>$val){

echo "==$val";

}

echo "<br/>";

}

$res->free();

$mysqli->close();

?>

在mysqli扩展中提供四种方式来获取mysqli result结果集:

  • <—>  mysql_fetch_array
  • <—>  mysql_fetch_assoc
  • <—>  mysql_fetch_object
  • <—>   mysql_fetch_row