0

I see there are many other similar posts regarding similar problems out there, but no one of them solved my problem.

I have the following .php file:

<?php
$servername = "localhost";
$username = "myusername";
$password = "mypassword";

// Create connection
$conn = mysqli_connect($servername, $username, $password);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";

$sql = "SELECT DISTINCT fase FROM tornei WHERE categoria='18' AND edizione='4' AND anno='2015'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "fase: " . $row["fase"];
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
?> 

The query correctly returns the expected result when executed on a MySQL client:

+--------+
| fase   |
+--------+
| gironi |
+--------+

In the logs, I get the following error:

PHP Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/admin/domains/domain.com/public_html/query.php on line 18
2
  • 1
    You should call mysqli_error() after you call the query, to see if there are errors in your statement or the db connection is not open Commented Oct 20, 2015 at 8:03
  • Try looking at the output of mysqli_error($conn) and see if that hints towards any issues. Commented Oct 20, 2015 at 8:04

1 Answer 1

2

You have not put the "database" name in mysqli_connect. Correct syntax is here:

$con=mysqli_connect("localhost","my_user","my_password","my_db");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.