<?php
header("Content-type:text/html;charset=utf-8");
//mysqli操作mysql数据库(面向对象)
//1.创建mysqli对象
$mysqli=new Mysqli("localhost","root","root","worddb");
//验证是否ok
if($mysqli->connect_error){
die("连接失败".$mysqli->connect_error);
}else{
echo "链接ok<br/>";
}
//2.操作数据库
$sql="select * from words";
//$res是结果集.mysqli result
$res=$mysqli->query($sql);
//3.处理结果
while($row=$res->fetch_row()){
foreach($row as $key=>$val){
echo "--$val";
}
echo "<br/>";
}
//4.关闭资源
$res->free();
?>