注意大写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);

 

版权声明:本文为79524795原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/79524795-Tian/p/16945205.html