mysqli_query()期望参数1和mysqli_fetch_array()期望参数1 [重复]

I got this error when I run my php file

  1. Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp\www\ims\graphdata.php on line 7

  2. Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\ims\graphdata.php on line 15

This is my php code:

<?php

$sql = "SELECT YEAR(borrowDate) as year_val, MONTH(borrowDate) as month_val ,COUNT(*) as total FROM itemrecord GROUP BY YEAR(borrowDate), MONTH(borrowDate);";

$result = mysqli_query($sql, $conn);

//start the json data in the format Google Chart js/API expects to receive it
$data = array('cols' => array(array('label' => 'Year', 'type' => 'number'),
                              array('label' => 'Month', 'type' => 'number'),
                              array('label' => 'Total', 'type' => 'number')),
              'rows' => array());

while($row = mysqli_fetch_array($result)){
  array_push($data['rows'], array('c' => array(
  array('v' => $row['Year']),
  array('v' => $row['Month']),
  array('v' => $row['Total']))));
  }  

$jsonData = json_encode($data);  
echo $jsonData; 

?>
</div>

You are using the mysqli_query function wrong. See http://php.net/manual/en/mysqli.query.php

In your case you are using procedural style, but don' provide the link variable in the correct position. Either add it as the first parameter oder use OO style.

Edit: Example for procedural style:

$result=mysqli_query($conn,$sql);