public function cadCliente(Cliente $objCliente) { $conexao = $this->abreConexao(); $sql = "INSERT INTO " . TBL_CLIENTES . " SET\n nome = '" . $objCliente->getNome() . "',\n email = '" . $objCliente->getEmail() . "',\n senha = '" . $objCliente->getSenha() . "',\n telefone = '" . $objCliente->getTelefone() . "',\n dataNascimento = '" . $objCliente->getDataNascimento() . "',\n cpf = '" . $objCliente->getCpf() . "',\n sexo = '" . $objCliente->getSexo() . "',\n status = 1\n dataCadastro = NOW()\n "; $conexao->query($sql) or die($conexao->error); $idCliente = $conexao->insert_id; return $idCliente; }
/** * Realiza atualização dos dados do cliente * @param Cliente $cliente */ public function atualizar(Cliente $cliente) { $query = "UPDATE clientes SET " . "nome = :nome, " . "email = :email, " . "ddd_telefone =:ddd_telefone, " . "telefone = :telefone, " . "ddd_celular = : ddd_celular, " . "celular = :celular " . "WHERE id_cliente = :id_cliente"; $stmt = $this->conexao->prepare($query); $stmt->bindValue(":nome", $cliente->getNome(), PDO::PARAM_STR); $stmt->bindValue(":email", $cliente->getEmail(), PDO::PARAM_STR); $stmt->bindValue(":ddd_telefone", $cliente->getDddTelefone(), PDO::PARAM_STR); $stmt->bindValue(":telefone", $cliente->getTelefone(), PDO::PARAM_STR); $stmt->bindValue(":ddd_celular", $cliente->getDddCelular(), PDO::PARAM_STR); $stmt->bindValue(":celular", $cliente->getCelular(), PDO::PARAM_STR); $stmt->execute(); }
public function persist(Cliente $cliente) { try { $stmt = $this->pdo->prepare("INSERT INTO Cliente(nome,endereco, telefone, tipo, grau_importancia, endereco_cobranca)\n VALUES (:nome, :endereco, :telefone, :tipo, :grau_importancia, :endereco_cobraca)"); $stmt->bindParam(':nome', $cliente->getNome()); $stmt->bindParam(':endereco', $cliente->getEndereco()); $stmt->bindParam(':telefone', $cliente->getTelefone()); $stmt->bindParam(':tipo', $cliente->getTipo()); $stmt->bindParam(':grau_importancia', $cliente->getGrauImportancia()); $stmt->bindParam(':endereco_cobraca', $cliente->getEnderecoCobranca()); $stmt->execute(); } catch (\PDOException $e) { return $e->getMessage(); } }
/** * Rende persistenti le modifiche all'anagrafica di un cliente sul db * @param Cliente $c il cliente considerato * @param mysqli_stmt $stmt un prepared statement * @return int il numero di righe modificate */ private function salvaCliente(Cliente $c, mysqli_stmt $stmt) { $query = " update clienti set \n username = ?,\n password = ?,\n email = ?,\n nome = ?,\n cognome = ?\n where clienti.id = ?\n "; $stmt->prepare($query); if (!$stmt) { error_log("[salvaCliente] impossibile" . " inizializzare il prepared statement"); echo 'impossibile" . " inizializzare il prepared statement'; return 0; } if (!$stmt->bind_param('sssssi', $c->getUsername(), $c->getPassword(), $c->getEmail(), $c->getNome(), $c->getCognome(), $c->getId())) { error_log("[salvaCliente] impossibile" . " effettuare il binding in input"); echo 'impossibile" . " effettuare il binding in input'; return 0; } if (!$stmt->execute()) { error_log("[caricaRegistrati] impossibile" . " eseguire lo statement"); echo 'impossibile" . " eseguire lo statement'; return 0; } return $stmt->affected_rows; }
/** * Rende persistenti le modifiche all'anagrafica di uno studente sul db * @param Cliente $s lo studente considerato * @param mysqli_stmt $stmt un prepared statement * @return int il numero di righe modificate */ private function salvaCliente(Cliente $c, mysqli_stmt $stmt) { $query = " UPDATE clienti SET \n password = ?,\n nome = ?,\n cognome = ?,\n via = ?,\n civico = ?,\n citta = ?,\n cap = ?,\n telefono = ?\n WHERE clienti.id = ?"; $stmt->prepare($query); if (!$stmt) { error_log("[salvaCliente] impossibile" . " inizializzare il prepared statement"); return 0; } if (!$stmt->bind_param('ssssissii', $c->getPassword(), $c->getNome(), $c->getCognome(), $c->getVia(), $c->getCivico(), $c->getCitta(), $c->getCap(), $c->getTelefono(), $c->getId())) { error_log("[salvaCliente] impossibile" . " effettuare il binding in input 2"); return 0; } if (!$stmt->execute()) { error_log("[caricaIscritti] impossibile" . " eseguire lo statement"); return 0; } return $stmt->affected_rows; }
require_once 'init.php'; include_once 'clientes.class.php'; //validação da imagem $dadosOK = true; //pega os dados do formulário $id = isset($_POST['id']) ? $_POST['id'] : null; $name = isset($_POST['txtNome']) ? $_POST['txtNome'] : null; $email = isset($_POST['txtEmail']) ? $_POST['txtEmail'] : null; $dataCadastro = isset($_POST['txtData']) ? $_POST['txtData'] : null; //validação simples se campos estão vazios if (empty($name) || empty($dataCadastro) || empty($email)) { echo "Campos devem ser preenchidos!!"; exit; } //instancia objeto cliente $cliente = new Cliente($name, $email, $dataCadastro); //atualiza o BD $PDO = db_connect(); $sql = "UPDATE clientes SET nomeCliente = :name, email = :email, dataCadastro = :data WHERE idCliente = :id"; $stmt = $PDO->prepare($sql); $stmt->bindParam(':name', $cliente->getNome()); $stmt->bindParam(':email', $cliente->getEmail()); $stmt->bindParam(':data', $cliente->getDataCadastro()); $stmt->bindParam(':id', $id, PDO::PARAM_INT); if ($stmt->execute()) { header('Location: index.php'); } else { echo "Erro ao alterar"; print_r($stmt->errorInfo()); }