-4

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.

AddWeb Solution Pvt Ltd
  • 20,310
  • 5
  • 23
  • 55
Archit
  • 31
  • 8
  • 1
    Is there any error? If not try this, /* check connection */ `if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }` – AddWeb Solution Pvt Ltd Jan 11 '16 at 05:12

3 Answers3

0

Replace with this I hope this work.As mysqli_fetch_assoc was deprecated in PHP 5.5.0

$row = mysql_fetch_assoc($result);
Wasiq Muhammad
  • 2,910
  • 3
  • 15
  • 27
  • It's `mysql_*` that has deprecated, not `mysqli_*` – A J Jan 11 '16 at 05:13
  • Thanks all for your responses. The problem is with the table name used in query. The table name is case sensitive on godaddy (for Database and in php code). While in localhost, it was not case sensitive. – Archit Jan 14 '16 at 15:57
0

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
A J
  • 3,827
  • 13
  • 38
  • 52
0

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!

AddWeb Solution Pvt Ltd
  • 20,310
  • 5
  • 23
  • 55