<?php
$serverName = "servername";
$connectionInfo = array("Database"=>"DB", "UID"=>"user1", "PWD"=>"[email protected]");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if($conn) {
echo "Connection established.<br />";
}
else{
echo "Connection could not be established.<br />";
die(print_r(sqlsrv_errors(), true));
}
$sql = "SELECT
COUNT(CASE WHEN online = 'Yes' THEN city END) AS o_total,
COUNT(CASE WHEN online = 'No' THEN city END) AS o_offline,
COUNT(*) as t_total,
COUNT(CASE WHEN online = 'Yes' AND channel='Name1' THEN city END) AS o_Name1,
COUNT(CASE WHEN channel='Name1' THEN city END) AS t_Name1,
COUNT(CASE WHEN online = 'YES' AND channel='Name2' THEN city END) AS o_Name2,
COUNT(CASE WHEN channel='Name2' THEN city END) AS t_Name2,
COUNT(CASE WHEN online = 'Yes' AND channel='Name3' THEN city END) AS o_Name3,
COUNT(CASE WHEN channel='Name3' THEN city END) AS t_Name3,
COUNT(CASE WHEN online = 'Yes' AND channel='Name4' THEN city END) AS o_Name4,
COUNT(CASE WHEN channel='Name4' THEN city END) AS t_Name4,
city FROM wmm group by city";
$result = $conn->query($sql);
$array = new stdClass();
if ($result->num_rows > 0) {
while($row = sqlsrv_fetch_assoc($result)) {
$array->$row['city'] = $row;
}
echo json_encode($array);
}
?>
我有錯誤=>致命錯誤:調用一個成員函數查詢()非對象上在C:\ XAMPP \ htdocs中\用戶\ File.php上線
呼叫一個成員函數查詢()非對象上
請幫我提前
如果你使用'sqlsrv_query'功能,同時傳遞'$ conn'並在「連接建立」條件塊一個簡單的測試查詢嗎? http://php.net/manual/en/function.sqlsrv-query.php –