PHP警告:mysqli_query()至少需要2个参数,即1

时间:2019-03-16 18:43:37

标签: php mysql

  

我不知道怎么了,我得到一个错误。帮我。预先谢谢你。

PHP代码

<?php
//DATABASE
$con=mysqli_connect("localhost", "root", "pw1234", "mr_system_db");

if(mysqli_connect_errno($con)) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();   
}



//$Today = $_POST['today'];


$now_date = date("Y-m-d");
echo $now_date;
//쿼리
$query = "SELECT MR_Dept_TB_Dept_NO, MR_MtRoom_TB_MtRoom_NO, MR_Info_Stime, MR_Info_Etime, mr_info_date
         FROM mr_info_tb where mr_info_date =  '$now_date'";
  

错误点! $结果= mysqli_query($查询);

     

mysqli_query()至少需要2个参数,给定1个

$result = mysqli_query($query); 

if(!$result ) 
  

错误点* mysqli_error()恰好需要1个参数,给定0个参数

die ( "Database access failed  : "  . mysqli_error());


    while ($row = mysqli_fetch_object($result)) {
        $arr[] = $row;  
    }
    echo json_encode($arr, JSON_UNESCAPED_UNICODE);


    mysqli_free_result($result);
    mysqli_close($con);

?>

1 个答案:

答案 0 :(得分:0)

您应该更改

$result = mysqli_query($query);$result = mysqli_query($con,$query);

mysqli_error()mysqli_error($con)