1
I’m having a problem entering data in the database using PDO and do not know the reason, in my view everything seems to be right, follow below the codes.
Model class
class User {
private $id;
private $nome;
public setNome($nome){
$this->nome = $nome;
}
public getNome(){
return $this->nome;
}
}
DAO class
class UsuarioDao implements Dao {
private $conexao;
function __construct(){
$connection = new Connection();
$this->conexao = $connection->getConnection();
}
public function insert($user){
try {
$query = "INSERT INTO usuarios(nome) VALUES(:nome)";
$this->conexao->prepare($query);
$this->conexao->bindValue(':nome',$user->getNome(),PDO::PARAM_STR);
return $this->conexao->execute();
}catch(PDOException $e){
echo $e->getMessage();
}
}
Instance of classes
require_once('User.class.php');
require_once('UserDao.class.php');
class Teste {
$user = new User();
$user->setNome('Gabriel');
$userDao = new UserDao();
$userDao->insert($user);
}
About the error log no message appears, only the error message 500.
And I’m getting error 500 every time I run this code, I’d like someone to help me find the error in this code. I started learning PHP now I have more knowledge in JAVA taking advantage of the question you know some ORM framework like Hibernate for PHP ?
The first thing is to check the PHP and/or http server error log for the problem. Why put the User class if you don’t show the instantiation in the code?
– Bacco
It would be good to [Dit] the question and put all the relevant parts, including the instantiation. Anyway, it’s pretty certain that the answer to the problem lies in the server error log.
– Bacco