-1

This is my code in model..

function installed(){
    $query_str = "SHOW TABLES";
    $query = $this->db->query($query_str);
    if($query->num_rows() == 0){
      redirect('install');
    }
}

So many questions on StackOverflow but I haven't found any answer related to scenario. So what I am doing wrong?

Qirel
  • 25,449
  • 7
  • 45
  • 62
nisha
  • 25
  • 5
  • `num_rows` is not a function, it's a variable. Try `$query->num_rows` instead. – Qirel Mar 20 '16 at 11:39
  • @Qirel No I'm using PDO it will be a function i think – nisha Mar 20 '16 at 12:30
  • `num_rows` is a `mysqli_` variable, not a PDO one. Try [`$query->rowCount()`](http://php.net/manual/en/pdostatement.rowcount.php), but that function might not always work with all databases. Read the documentation. – Qirel Mar 20 '16 at 12:32

1 Answers1

0

I would assume that, your $this->db is a mysqli instance. Hence, making a ->query(...) call should gives you a mysqli_result instance on success. So your $query should simply be a mysqli_result object, and hence num_rows should be a property, not a function at all. You are using it wrong.

Check here: http://php.net/manual/en/mysqli-result.num-rows.php. They have a sample code there.

So what Qirel mentioned is correct.

Lionel Chan
  • 7,894
  • 5
  • 40
  • 69