SergeProtector SergeProtector -4 years ago 198
MySQL Question

Warning: mysql_query() expects parameter 2 to be resource, object given

I keep getting this error when trying to execute this query.

$conn = new mysqli($servername, $username, $password, $dbname);

$query = "SELECT * FROM entry";
$result = mysql_query($query, $conn);
$count = mysql_num_rows($result);
echo $count;

Answer Source

Since mysql_* is deprecated so please try this:-

$conn = mysqli_connect($server,$username,$password,$database) or die(mysqli_connect_error());

$query = "SELECT * FROM entry";

$result = mysqli_query($conn,$query) or die(mysqli_error($conn));

$count = mysqli_num_rows($result);
echo $count;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download