mysqli_query()期望参数1和mysqli_fetch_array()期望参数1

时间:2015-11-22 08:58:48

标签: php mysqli

运行php文件时出现此错误

  
      
  1. 警告:mysqli_query()要求参数1为mysqli,第7行的C:\ wamp \ www \ ims \ graphdata.php中给出的字符串

  2.   
  3. 警告:mysqli_fetch_array()要求参数1为mysqli_result,在第15行的C:\ wamp \ www \ ims \ graphdata.php中给出null

  4.   

这是我的php代码:

<?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; 

?>

1 个答案:

答案 0 :(得分:1)

您使用mysqli_query功能错误。见http://php.net/manual/en/mysqli.query.php

在你的情况下,你使用程序风格,但不要提供正确位置的链接变量。将其添加为第一个参数或使用OO样式。

编辑:程序样式的示例:

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