I've copied the W3 schools code for performing a mysqli row count function, but when I input my variables, the returned result is always '1'. I have checked my SQL code by entering it directly into phpMyAdmin, which returns the correct result.
This is my code:
<?php
$con = mysqli_connect("x", "x", "x", "x");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT COUNT(*) FROM `Existing_Bookings`";
if ($result=mysqli_query($con,$sql))
{
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
printf("Result set has %d rows.\n",$rowcount);
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
I just wondered if anyone can see any obvious reason behind this? My server is running PHP 5.6 which is why I have ensured I am using mysqli, rather than mysql for this.