0

Being 'test' a table and a 'test_view' a simply view of 'table' (CREATE VIEW test_view AS SELECT * from test)

Why the following code doesn't work?

$stmt = mysqli_prepare($conn, "SELECT * FROM test_view LIMIT 3");
mysqli_stmt_execute($stmt);

Results is:

array(3) {
      ["errno"]=>
      int(1615)
      ["sqlstate"]=>
      string(5) "HY000"
      ["error"]=>
      string(42) "Prepared statement needs to be re-prepared"
    }

While this one with table works

$stmt = mysqli_prepare($conn, "SELECT * FROM test LIMIT 3");
mysqli_stmt_execute($stmt);

It seams that prepare doesn't work on views. Any suggestions?

Fabrix
  • 39
  • 7
  • 2
    Where exactly are you getting that result from? If you turn on mysqli error reporting it should give you an exception from mysql to explain why any particular query has failed. There is nothing special about views in this context. https://stackoverflow.com/a/22662582/5947043 – ADyson Nov 01 '21 at 09:24
  • Tbh, if you're not using any parameters in your query, just go with `$conn->query()` (or `mysqli_query()` if you rather do it function-style). There isn't much to "prepare" if you're not using any parameters. – M. Eriksson Nov 01 '21 at 09:31
  • @ADyson Error got from `$stmt['error_list]`. SQL execption is the same `Uncaught mysqli_sql_exception: Prepared statement needs to be re-prepared in /home/***.php:14 Stack trace: #0 /home/***php(14): mysqli_stmt_execute(Object(mysqli_stmt)) #1 {main}` @MagnusEriksson This is just a simple example, I need the prepare to use parameters. – Fabrix Nov 01 '21 at 10:23

0 Answers0