问题描述
运行php
文件时出现此错误
-
警告:mysqli_query()期望参数1为mysqli,第7行的C:\ wamp \ www \ ims \ graphdata.php中给出的字符串
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp\www\ims\graphdata.php on line 7
警告:mysqli_fetch_array()期望参数1为mysqli_result,在第15行的C:\ wamp \ www \ ims \ graphdata.php中给出空值
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\ims\graphdata.php on line 15
这是我的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;
?>
推荐答案
您正在使用mysqli_query
函数错误.参见 http://php.net/manual/en/mysqli.query.php
You are using the mysqli_query
function wrong. See http://php.net/manual/en/mysqli.query.php
在您的情况下,您使用的是过程样式,但请不要在正确的位置提供链接变量.要么将其添加为使用OO样式的第一个参数.
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.
过程样式示例:
$result=mysqli_query($conn,$sql);
这篇关于mysqli_query()期望参数1,而mysqli_fetch_array()期望参数1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!