数据库总结

一、数据库查询语句

      描述:去数据库的指定表中根据条件查询语句

$con=mysqli_connect('localhost','root','','librarydb');

       mysqli_query($con,'set names utf8');

       mysqli_query($con,'set character_set_client=utf8');

       mysqli_query($con,'set character_set_results=utf8');

       $sql="select * from book where bookId='1' ";

       $result=$con->query($sql);

       if($result->num_rows>0){

               $info=[];

               for($i=0;$row=$result->fetch_assoc();$i++){

                        $info[$i]=$row;

       }

       print_r($info);

}

二、数据库修改语句

 $con=mysqli_connect('localhost','root','','librarydb');

mysqli_query($con,'set names utf8');

mysqli_query($con,'set character_set_client=utf8');

mysqli_query($con,'set character_set_results=utf8');
$sql="update book set bookName='鲁滨逊漂流记' where bookId='123' ";
$result=$con->query($sql);
if($result){
    	echo '修改成功';
    }else{
    	echo '修改失败,请重新修改';
    }

三、数据库增加语句

$con=mysqli_connect('localhost','root','','librarydb');
if($con){
	echo '连接成功Loading...';

    mysqli_query($con,'set names utf8');
    mysqli_query($con,'set character_set_client=utf8');
    mysqli_query($con,'set character_set_results=utf8');

    $sql="insert into book (bookId,bookName,bookAuthor,bookPrice,bookNum) values('3','时间科学','不知道','85','16')";

    $result=$con->query($sql);

    if($result){
    	echo '添加成功';
    }else{
    	echo '添加失败,请重新添加';
    }

}else{
	echo '连接失败,请重连';
}

四、数据库删除语句

$con=mysqli_connect('localhost','root','','librarydb');
if($con){
	echo '连接成功Loading...';

    mysqli_query($con,'set names utf8');
    mysqli_query($con,'set character_set_client=utf8');
    mysqli_query($con,'set character_set_results=utf8');

    $sql="delete from book where bookName='时间科学'";

    $result=$con->query($sql);

    if($result){
    	echo '删除成功';
    }else{
    	echo '删除失败,请重新删除';
    }

}else{
	echo '连接失败,请重连';
}

 五、html,数据库,php前后端交互

      1、引入jquery框架

      2、需要和后台交互的话,调用 ajax 方法

            ajax方法需要一系列参数:type : 'post/get',

                                                     url : '给一个目标网址(一定要加http)',

                                                     datatype : 'json',

                                                     data : (data是post专有的){  ...  },

                                                     success : function(data){

                                                              console.log(data);

               }

在php中内置了两个对象用来接收前端发来的消息

    $GET:用于获取在前端通过get请求发来的信息

    $SET:用于获取在前端通过post请求发来的信息

      

猜你喜欢

转载自blog.csdn.net/qq_42129143/article/details/80229240