2

UPDATE: The query is working perfectly as follows; the error solely appears when I select from the view.

$query = "
SELECT ModuleID, ModuleName, Credits, Lecturer, Room, EmployeeID, Forename, Surname, RoomID, RoomCode
FROM ((Module 
INNER JOIN Employee ON Module.Lecturer = Employee.EmployeeID) 
INNER JOIN Room ON Module.Room = Room.RoomID)
";

$result = $DBH->prepare($query);
$result->execute();
$data = $result->fetchAll();

I'm receiving the following error when trying to SELECT * FROM a view I created. (Selecting from a table works perfectly).

Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared'

I have no issues when using

SELECT * FROM Module

Here is my query:

$query = "
SELECT * FROM module_info
";

$result = $DBH->prepare($query);
$result->execute();
$data = $result->fetchAll();

The view I created:

CREATE VIEW module_info 
AS
SELECT ModuleID, ModuleName, Credits, Lecturer, Room, EmployeeID, Forename, Surname, RoomID, RoomCode
FROM ((Module 
INNER JOIN Employee ON Module.Lecturer = Employee.EmployeeID) 
INNER JOIN Room ON Module.Room = Room.RoomID);
Xander
  • 991
  • 1
  • 13
  • 32

1 Answers1

3

The solution in this instance was as follows:

Emulation of prepared statements needs to be enabled.

In the connection file, the following line

PDO::ATTR_EMULATE_PREPARES   => false,

needs to be changed like so:

PDO::ATTR_EMULATE_PREPARES   => true,

In other instances it appears the solution may be to increase the table_definitition_cache

Xander
  • 991
  • 1
  • 13
  • 32