PHP原生增删改查
注意大写SQL语句
1.连接数据库
$con=mysqli_connect(“localhost”,”admin”,”123456″,”ljm_web”);
地址 账号 密码 数据库名
if (mysqli_connect_errno($con))
{
echo “连接 MySQL 失败: ” . mysqli_connect_error();
}
2.增加
mysqli_query($con,”SELECT * FROM ljm_liuyan”);
mysqli_query($con,”INSERT INTO ljm_liuyan (wen,uid,kind) VALUES ( ‘$wen’, ‘$uid’ , ‘$sa’)”); //INSERT INTO ljm_liuyan (name, url, alexa, country)VALUES (‘百度’,’https://www.baidu.com/’,’4′,’CN’)
mysqli_close($con);
3.查询
$ljmsql3=”SELECT * FROM `ljm_admin` WHERE ljm_aid = “.$adminid;
$ljmres3=mysqli_query($conn,$ljmsql3);
if (!$ljmres3) {
echo ‘<script>alert(“数据出现问题”);location.href=”index.php”;</script>’;
}
$tourresult = $ljmres3->fetch_array() ?? ”; // 查询出来的对象 转为数组
var_dump($tourresult);
die;
查询多条
$con=mysqli_connect("localhost","yp","123456","yp"); $sql2="SELECT * FROM `aaaa` WHERE uip = '".$uip."'"; $res=mysqli_query($con,$sql2); $ins = [];$ia = 0; while ($row = $res->fetch_assoc()) { $ia ++; $ins[$ia]['yu'] = $row['yu']; $ins[$ia]['ip'] = $row['ip']; if( $row['static'] == 0 ){ $ins[$ia]['static'] = '未审核'; }else{ $ins[$ia]['static'] = '已审核'; } } var_dump($ins);