1
I am developing a small application that will serve to update my knowledge, however, in the development of it I came across some inconsistent situations. I would like my "CRUD" to return a "div" that will display an "Alert" css when run by the browser, but when run, only Alert is displayed and all the rest of the form disappears (running on the same page).
database.class.php (initial project, only returns the error)
// Delete
public function deleteDB($sql,$params=null){
$query=$this->connect()->prepare($sql);
$query->execute($params);
$rs = $query->rowCount() or die(print_r($query->errorInfo(),true));
self::__destruct();
return $rs;
}
Short HTML (example):
<?php
include './inc/database.class.php';
?>
<html>
<body>
<?php
$PDO = new database();
$resultado = $PDO->deleteDB("delete from usuario where login = :login and password = :password",array(':login' => "teste",':password' => "1234"));
?>
<div class="form">
<!-- inputs -->
<!-- buttons -->
</div>
</body>
</html>
database.class.php (change)
public function deleteDB($sql,$params=null){
$query=$this->connect()->prepare($sql);
$query->execute($params);
$rs = $query->rowCount() or die(print_r("<div class='alert' ... etc>",true));
self::__destruct();
return $rs;
}
Finally, I thought of other ways, even a new class to deal with errors, but I would like something simple like the example shown above. If anyone can help me, I’d appreciate it ;)
die(string)
closes the execution, is like theexit(int)
. Changedie
forecho "<div ...>"
.– William Novak
But in this way the connection would remain active, that would be appropriate?
– Carlos
No, no. The
die
does not close the connection. Thedie
terminates the application, hence the connection. In any case, you want to terminate only the connection, not your application. See To close the Connection, you need to Destroy the Object by Ensuring that all remaining References to it are Deleted-you do this by assigning NULL to the variable that Holds the Object..– William Novak