I'm using object-oriented MySQLi prepared statements and I'm getting the hang of it but there's something I don't quite understand. When I use INSERT, UPDATE, REPLACE and DELETE I can use affected_rows to know if I was successful, that the query actually did something. However, when I want to see if anything was returned by my SELECT statement I turn to num_rows in hope that I can see how many rows were returned before I try to use the result as an array. The problem I have is I always get the following: Notice: Undefined property: mysqli::$num_rows in C:\UniServer\www\website\index.php on line 60 So, should I be using num_rows or something different? How do you guys recommend that I first check to see if the result variable has received something before I try to use it as an object? Here's some code that shows what I've been doing:
<?php $connection = new mysqli("localhost", "root", "password", "website_database"); $result = $connection->prepare("SELECT * FROM `users` WHERE email = ? AND password = ? LIMIT 1"); $result->bind_param("ss", $email, $password); $result->execute(); if ($connection->num_rows > 0) { // Do something meaningful if there was actually a row returned, otherwise don't do anything. // I don't want to just go straight to using result with "$row = $result->fetch_row();" // because I don't even know if there was a user with that email and password.} ?>