This question already has an answer here:
I have a code like below:
$sql="SELECT * FROM $tbl_name WHERE AdminId='$AdminId'";
$result=mysqli_query($conn,$sql);
$row = mysqli_fetch_assoc($result);
and $conn
is declared like below in a separate connection file:
<?php
$host="1.2.3.4:1234"; // Host name
$username="xyz"; // Mysql username
$password="abc"; // Mysql password
$db_name="dbname"; // Database name
$conn=@mysqli_connect("$host", "$username", "$password")or die("Cannot connect to the server");
mysqli_select_db($conn,"$db_name")or die("Cannot select DB");
?>
While running the php page, I am getting below error:
mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given
While, this query works fine with my localhost.
Any suggestion ?
Thanks.
</div>
Replace with this I hope this work.As mysqli_fetch_assoc was deprecated in PHP 5.5.0
$row = mysql_fetch_assoc($result);
Try in the following way.
$resultArr = array();//to store results
$result=$conn->query($sql);//execute query here
while($row = $result->fetch_assoc())
{
$resultArr[] = $row;//storing results
}
print_r($resultArr);//print the returned row
Try this:
$sql="SELECT * FROM $tbl_name WHERE AdminId='$AdminId'";
if ($result = $mysqli->query($sql)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
}
}
This may help you!