0

I am trying to find the number of rows in a table and have tried the following:

$query = $mysqli->query("SELECT * FROM tablename WHERE DIR='$dir'");
$num_rows = mysql_num_rows($query);

but i get the following warning when the script is run

Warning: mysql_num_rows() expects parameter 1 to be resource, object given

any ideas?

  • 1
    your mixing mysql and mysqli and procedural vs oop –  Aug 25 '16 at 22:59
  • Try, `mysqli`_num_rows, you are using `mysql`_num_rows – Teymur Mardaliyer Lennon Aug 25 '16 at 23:00
  • mysqli may return different type than mysql. If you want to use `mysql_num_rows()`, use `mysql_query()`. – Eric Aug 25 '16 at 23:01
  • using mysql_num_rows i get: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given – Payton Michaels Aug 25 '16 at 23:01
  • 1
    you cant just add an **i**, the syntax is different, and your still mixing procedural with oop –  Aug 25 '16 at 23:03
  • 2
    **WARNING**: When using `mysqli` you should be using [parameterized queries](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [`bind_param`](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add user data to your query. **DO NOT** use string interpolation or concatenation to accomplish this because you have created a severe [SQL injection bug](http://bobby-tables.com/). **NEVER** put `$_POST` or `$_GET` data directly into a query, it can be very harmful if someone seeks to exploit your mistake. – tadman Aug 25 '16 at 23:04

0 Answers0