abstract:<?phpheader("Content-type: text/html; charset=utf-8");date_default_timezone_set("PRC");$con = @mysqli_connect('127.0.0.1','root','root','hediwangluo&
<?php
header("Content-type: text/html; charset=utf-8");
date_default_timezone_set("PRC");
$con = @mysqli_connect('127.0.0.1','root','root','hediwangluo','3306');
if (!$con)
{
exit( "连接 MySQL 失败: " . mysqli_connect_error());
}
//设置数据库字符集编码
mysqli_query($con,"set character set 'utf8'");//读库
mysqli_query($con,"set names 'utf8'");//写库
/**
* 获取多条记录
*/
function getAll($sql,$result_type=MYSQLI_ASSOC)
{
global $con;
$result=mysqli_query($con,$sql);
if($result)
{
while(@$row=mysqli_fetch_array($result, $result_type)){
$data[]=$row;//查询返回 $data;
}
mysqli_free_result($result);//释放内存
}
return $data;
}
/**
* 返回满足条件的第一条记录
*/
function getOne($sql,$result_type=MYSQLI_ASSOC)
{
global $con;
$result=mysqli_query($con,$sql);
$row = mysqli_fetch_array($result,$result_type);
return $row;
}
/**
* 返回获取查询结果集的数量
*/
function getResultNum($sql){
global $con;
$res=mysqli_query($con,$sql);
return mysqli_num_rows($res);
}
/**
* @param {Object} $sql 删除一条数据,
* 返回bool值
*/
function delete_sql($sql){
global $con;
$res=mysqli_query($con,$sql);
if($res){
return true;
}else{
return false;
}
}
/**
* @param {Object} $sql增加数据
* 返回增加数据的id
*/
function add_sql($sql){
global $con;
$res= mysqli_query($con,$sql);
if($res){
return mysqli_insert_id($con);
}else{
return false;
}
}
Correcting teacher:查无此人Correction time:2019-06-26 14:54:59
Teacher's summary:完成的不错。pdo操作速度比之前的mysqli快很多,之后学习pdo。继续加油