note 130040 added to mysqli.begin-transaction
| From: | pep@gmail.com | Date: | Tue, 18 Feb 2025 12:06:40 +0000 |
| Subject: | note 130040 added to mysqli.begin-transaction | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221864@lists.php.net to get a copy of this message | ||
public function engadirPacente($pacente, $idsServizos)
{
try {
$this->conexion->beginTransaction();
$sql = 'INSERT INTO pacentes (nome, email, nacemento, alta) VALUES (:nome, :email,
:nacemento, :alta)';
$stm = $this->conexion->prepare($sql);
$stm->bindParam('nome', $pacente->nome);
$stm->bindParam('email', $pacente->email);
$stm->bindParam('nacemento', $pacente->nacemento);
$stm->bindParam('alta', $pacente->alta);
$stm->execute();
$idPacente = $this->conexion->lastInsertId();
$sqlPibote = 'INSERT INTO pacente_servizo (pacente_id, servizo_id) VALUES
(:pacente_id, :servizo_id)';
$stmPibote = $this->conexion->prepare($sqlPibote);
foreach ($idsServizos as $id) {
$stmPibote->bindParam('pacente_id', $idPacente);
$stmPibote->bindParam('servizo_id', $id);
$stmPibote->execute();
}
$this->conexion->commit();
} catch (PDOException $e) {
$this->conexion->rollBack();
echo "Error para engadir o pacente: " . $e->getMessage();
}
}
public function borrarPacente($id)
{
try {
$this->conexion->beginTransaction();
$sqlPibote = 'DELETE FROM pacente_servizo WHERE pacente_id = :id';
$stmPibote = $this->conexion->prepare($sqlPibote);
$stmPibote->bindParam('id', $id);
$stmPibote->execute();
$sql = 'DELETE FROM pacentes WHERE id = :id';
$stm = $this->conexion->prepare($sql);
$stm->bindParam('id', $id);
$stm->execute();
$this->conexion->commit();
} catch (PDOException $e) {
$this->conexion->rollBack();
echo "Error para borrar o pacente: " . $e->getMessage();
}
}
}
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 2a02:9130:9c20:ac6e:44d7:df6a:48e8:d37b)
----
Manual Page -- https://php.net/manual/en/mysqli.begin-transaction.php
Edit -- https://main.php.net/note/edit/130040
Del: integrated -- https://main.php.net/note/delete/130040/integrated
Del: useless -- https://main.php.net/note/delete/130040/useless
Del: bad code -- https://main.php.net/note/delete/130040/bad+code
Del: spam -- https://main.php.net/note/delete/130040/spam
Del: non-english -- https://main.php.net/note/delete/130040/non-english
Del: in docs -- https://main.php.net/note/delete/130040/in+docs
Del: other reasons-- https://main.php.net/note/delete/130040
Reject -- https://main.php.net/note/reject/130040
Search -- https://main.php.net/manage/user-notes.php