$conn = new mysqli("localhost","root","root","(itcast)");
if($conn->connect_errno){
//die() 函数输出一条消息,并退出当前脚本。该函数是 exit() 函数的别名。
die("链接失败".$conn->connect_error);
}
//设置字符集
$conn->set_charset('utf8');
$id = $_GET['id'];
//2.执行sql(select * from t_student where studentid=?)
//需要执行的sql语句
$sql = "select id,name,sex,case sex when '0' then '男' when '1' then '女' else '其他' end sexa,birthday from student where id={$id} order by id";
$res = $conn->query($sql);
//3.处理结果集(结果集/false)
if($res!=false && $res->num_rows==1){
$data = $res->fetch_assoc();
}
//4.释放结果集 关闭连接
$res->free();
$conn->close();
PHP链接数据库new MySQL方式
最新推荐文章于 2021-03-29 00:37:14 发布