// Storing in the SQL table A ...
$tableADAO = new \app\model\tableADAO();
// An explicit SQL transaction is started...
$tableADAO->beginTransaction();
// The autocommit parameter is set to FALSE, so the row data are not committed in database after the call of the store method...
$tableADAO->store($rowA, FALSE);
// Storing in the SQL table B ...
$tableBDAO = new \app\model\tableBDAO();
$tableBDAO->store($rowB, FALSE); // No autocommit...
$tableCDAO = new \app\model\tableCDAO();
$tableCDAO->store($rowC, FALSE); // No autocommit...
// The SQL transaction is finally committed to apply the changes in the database.
$tableCDAO->commit();
static protected function action_enregistrer() {
/* Lecture des données de la requête HTTP */
$request = new \Request();
$row = $request->getValuesAsMap('IdEntrenamiento','IdEntrenador', 'Fecha' ,'IdEquipo' );
/* Enregistrement des données en Base de données */
$jugadorDAO = new tentrenamientoDAO();
$result = $jugadorDAO->store($row);
/*lectura de los campos del jugador*/
$requestJ = new \Request();
$rowJ = $requestJ->getValuesAsMap('IdEntrenamientoJugador',IdEntrenamiento,'IdJugador','Idposicion');
/* Enregistrement des données en Base de données */
$jugadorDAOJ = new \app\model\tnejentrenamientoDAO();
$resultJ = $jugadorDAOJ->store($rowJ);
/*lectura de los campos de la valoracion*/
$requestV = new \Request();
$rowV = $requestV->getValuesAsMap('IdEntrenamientoJugadorValoracion','IdEntrenamientoJugador','IdItems','Valoracion','comentario');
/* Enregistrement des données en Base de données */
$jugadorDAOV = new \app\model\tnejventrenamientoDAO();
$resultV = $jugadorDAOV->store($rowV);
/* Réponse retournée au contrôleur principal */
$response = new \Response();
if ($result) {
$response->setSuccessMessage('Guardar', 'Entrenamiento guardado correctamente.');
} else {
$response->setFailedMessage('Guardar', "El Entrenamiento no ha sido guardado.");
}
return $response;
}
Pruebo tu solución que seguro que como siempre es altamente efectiva.
Saludos
// Storing in the SQL table A ...
$tableADAO = new \app\model\tableADAO();
// An explicit SQL transaction is started...
$tableADAO->beginTransaction();
// The autocommit parameter is set to FALSE, so the row data are not committed in database after the call of the store method...
$rowA = array('col1'=>'value1','col2'=>'value2','col3'=>'value3');
$tableAId = $tableADAO->store($rowA, FALSE);
// Storing in the SQL table B ...
$tableBDAO = new \app\model\tableBDAO();
$rowB = array('col1'=>'value4','col2'=>'value5','col3'=>'value6');
$rowB['col_id_a'] = $tableAId;
$tableBId = $tableBDAO->store($rowB, FALSE); // No autocommit...
$tableCDAO = new \app\model\tableCDAO();
$rowC = array('col1'=>'value7','col2'=>'value8','col3'=>'value9');
$rowC['col_id_b'] = $tableBId;
$tableCDAO->store($rowC, FALSE); // No autocommit...
// The SQL transaction is finally committed to apply the changes in the database.
$tableCDAO->commit();