1
I am registering users in the system, but I can not know the result of my query in the database I tried to return the value of execute but I was not successful, some solution?
Note: I am already able to enter the data in the database
My bank code
<?php
class Banco{
private $conexao, $usuario;
public function __construct(Conexao $conexao, Usuario $usuario){
$this->conexao = $conexao->conectar();
$this->usuario = $usuario;
}
public function inserir(){
$query = 'insert into usuario(idUsuario, email, senha, nome) values(?, ?, ?, ?)';
$stmt = $this->conexao->prepare($query);
$stmt->bindValue(1,$this->usuario->__get('idUsuario'));
$stmt->bindValue(2,$this->usuario->__get('email'));
$stmt->bindValue(3,$this->usuario->__get('senha'));
$stmt->bindValue(4,$this->usuario->__get('nome'));
$stmt->execute();
}
public function excluir(){
}
public function recuperarRegistros(){
}
public function pesquisarUsuario($id){
$query = 'select idUsuario from usuario where id = ?';
$stmt = $this->conexao->prepare($query);
$stmt->bindValue(1,$this->usuario->__get('idUsuario'));
$stmt->execute();
}
}
?>
Page calling the operation
<?php
require_once '../../projetoPrivado/Banco.php';
require_once '../../projetoPrivado/Conexao.php';
require_once '../../projetoPrivado/Usuario.php';
echo'<pre>';
print_r($_POST);
echo '</pre>';
$conexao = new Conexao();
$usuario = new Usuario($_POST['nome'],$_POST['senha'], $_POST['email'], $_POST['id']);
$banco = new Banco($conexao, $usuario);
echo'<pre>';
print_r($usuario);
echo '</pre>';
// $banco->inserir();
$banco->pesquisarUsuario($_POST['id']);
?>
Although I find your answer valid, the question says.. "How to know if the query has returned true" ... What would be just
return $stmt->execute();
... But I think that’s what he really wants in his answer.– Andrei Coelho
Thank you, that’s right
– diogo.alves