面对对象数据库

<?php

//面向对象的方式访问数据库

//造对象 $db = new MySQLi("localhost","root","123","mydb");

//判断连接是否出错 /*if(mysqli_connect_error()) {  echo "连接失败!";  exit; }*/

!mysqli_connect_error() or die("连接失败!");

//写SQL语句 $sql = "insert into Info values('p010','张三',true,'n002','1988-2-3')";

//执行SQL语句,查询语句返回结果集对象,其他语句返回true或false $result = $db->query($sql);

//从结果集对象中读取数据 //$attr = $result->fetch_all(MYSQLI_BOTH); //以二维数组的方式返回所有数据 //$attr = $result->fetch_array(); //返回当前指针指向的这条数据 //$attr = $result->fetch_assoc(); //返回当前指针指向的这条数据(关联数组) //$attr = $result->fetch_object(); //返回对象 //$attr = $result->fetch_row(); //返回索引数组 //var_dump($attr); /* while($attr = $result->fetch_row()) {  var_dump($attr); }*/

//var_dump($result);

?>

原文地址:https://www.cnblogs.com/naqiang/p/5580544.html