I'm developing a simple system in which in my home.php
, I have a table that will be fed by a VIEW
of my database.
But even modifying in my CRUD
, he gives me the following error when I register a room:
Fatal error: Uncaught PDOException: SQLSTATE [HY000]: General error: 1393 Can not modify more than one base table through a join view 'prj_delta.vincular_hosp' in C: \ xampp \ htdocs \ prj_delta \ model \ Manager.class.php: 14 Stack trace: # 0 C: \ xampp \ htdocs \ prj_delta \ model \ Manager.class.php (14): PDOStatement-> Run () # 1 C: \ xampp \ htdocs \ prj_delta \ controller \ insert_quarto.php (11): Manager- > insertClient ('bind_path', Array) # 2 {main} thrown in C: \ xampp \ htdocs \ prj_delta \ model \ Manager.class.php on line 14
My manager class below:
<?php
class Manager extends Conexao {
public function insertClient($table, $data) {
$pdo = parent::get_instance();
$fields = implode(", ", array_keys($data));
$values = ":".implode(", :", array_keys($data));
$sql = "INSERT INTO $table ($fields) VALUES ($values)";
$statement = $pdo->prepare($sql);
foreach($data as $key => $value) {
$statement->bindValue(":$key", $value, PDO::PARAM_STR);
}
$statement->execute();
}
public function listClient($table) {
$pdo = parent::get_instance();
$sql = "SELECT * FROM $table ORDER BY id_quarto ASC";
$statement = $pdo->query($sql);
$statement->execute();
return $statement->fetchAll();
}
public function deleteClient($table, $id) {
$pdo = parent::get_instance();
$sql = "DELETE FROM $table WHERE id = :id";
$statement = $pdo->prepare($sql);
$statement->bindValue(":id", $id);
$statement->execute();
}
public function getInfo($table, $id) {
$pdo = parent::get_instance();
$sql = "SELECT * FROM $table WHERE id = :id";
$statement = $pdo->prepare($sql);
$statement->bindValue(":id", $id);
$statement->execute();
return $statement->fetchAll();
}
public function updateClient($table, $data, $id) {
$pdo = parent::get_instance();
$new_values = "";
foreach($data as $key => $value) {
$new_values .= "$key=:$key, ";
}
$new_values = substr($new_values, 0, -2);
$sql = "UPDATE $table SET $new_values WHERE id = :id";
$statement = $pdo->prepare($sql);
foreach($data as $key => $value) {
$statement->bindValue(":$key", $value, PDO::PARAM_STR);
}
$statement->execute();
}
}
?>
Here is my insert_quarto.php
<?php
include_once '../model/Conexao.class.php';
include_once '../model/Manager.class.php';
$manager = new Manager();
$data = $_POST;
if(isset($data) && !empty($data)) {
$manager->insertClient("vincular_hosp", $data);
header("Location: ../home.php?client_add_success");
}
?>