C9 – How to get the result of the query and how to get the number of the rows from the query?

I wrote this function that get user name and need to check if the user is already in the DB.

This is my code:

 $conn = new mysqli($servername, $username, $password, $database, $dbport);
 mysql_select_db("myDB",$conn);
 //$sql="CALL checkIfExsist(".$name.")";
 $sql = "select * from Users where userName='".$name."' LIMIT 1;";
 $myData = $conn-> query($sql);
 $rowc = mysqli_num_rows($myData);
 printf("Result set has %d rows.\n", $rowc);
  if($rowc > 0)
  {
      echo "User ".$name." checked";

  }
  else
     echo "not exsist";

When I run this query in the terminal i get 1 row result, but in the consol I get: “Result set has 0 rows.”

What is the problem?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s