0

my first question so please feel free to keep me right.

When I use $stmt->get_result() with a SELECT query on a table in my MYSQL database, I get a result set as expected.

If I run exactly the same code on a MYSQL view, the get_result() returns false. This happens even if the view constitutes a simple "SELECT *" from the table in question.

In terms of code, this will return a result set:

$q =  "SELECT * FROM table_name";
if ($stmt = $con->prepare($q)) {
    $stmt->execute();
    if ($res = $stmt->get_result()) {
        echo "success";
    }     
    else
    {
        echo "fail";
        var_dump($res);
    }  
    $stmt->close();    
}  

This will return false in the var_dump:

$q =  "SELECT * FROM view_name";
if ($stmt = $con->prepare($q)) {
    $stmt->execute();
    if ($res = $stmt->get_result()) {
        echo "success";
    }     
    else
    {
        echo "fail";
        var_dump($res);
    }  
    $stmt->close();    
}  

Many thanks in advance for any pointers.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

0 Answers0