private static function connect()
 {
     try {
         $dsn = self::$driver . ':host=' . self::$host . ';port=' . self::$port . ';dbname=' . self::$dbname;
         self::$cnx = new PDO($dsn, self::$user, self::$password);
         return true;
     } catch (PDOException $e) {
         echo $e->getMessage();
     }
 }
 /**
  *  funcion para registrar un depto
  * @param type $id
  * @param type $nom
  * @return boolean|\PDOException
  * @throws PDOException
  */
 public static function newDepto($id, $nom)
 {
     try {
         $sql = "INSERT INTO depto (cod_depto, nom_depto) VALUES (" . $id . ", '{$nom}')";
         DataBaseClass::getCnx()->beginTransaction();
         $anwr = DataBaseClass::getCnx()->exec($sql);
         DataBaseClass::getCnx()->commit();
         if ($anwr !== false) {
             $anwr = true;
         } else {
             throw new PDOException("El Departamento {$id}, {$nom} ya han sido REGISTRADOS");
         }
         return $anwr;
     } catch (PDOException $e) {
         return $e;
     }
 }
 /**
  *  funcion para registrar un centro
  * @param type $id
  * @param type $desc
  * @param type $telefono
  * @param type $dir
  * @param type $codCiudad
  * @return boolean|\PDOException
  * @throws PDOException
  */
 public static function newCentro($id, $desc, $telefono, $dir, $codciudad)
 {
     try {
         $sql = "INSERT INTO centro (cod_centro, desc_centro, telefono, dir, cod_ciudad) VALUES (" . $id . ", '{$desc}', '{$telefono}', '{$dir}', '{$codciudad}')";
         DataBaseClass::getCnx()->beginTransaction();
         $anwr = DataBaseClass::getCnx()->exec($sql);
         DataBaseClass::getCnx()->commit();
         if ($anwr !== false) {
             $anwr = true;
         } else {
             throw new PDOException("El centro {$id}, {$desc} ya han sido REGISTRADOS");
         }
         return $anwr;
     } catch (PDOException $e) {
         return $e;
     }
 }
 public static function newCredencial($id, $usuario, $credencial)
 {
     try {
         $sql = "INSERT INTO usuario_credencial (id, usuario_id, credencial_id) VALUES (" . $id . ", {$usuario}, {$credencial})";
         DataBaseClass::getCnx()->beginTransaction();
         $anwr = DataBaseClass::getCnx()->exec($sql);
         DataBaseClass::getCnx()->commit();
         if ($anwr !== false) {
             $anwr = true;
         } else {
             throw new PDOException("This Credencial {$id} has already been REGISTERED");
         }
         return $anwr;
     } catch (PDOException $e) {
         return $e;
     }
 }
 /**
  * 
  * @param type $id
  * @param type $programa
  * @param type $fechaInicio
  * @param type $fechaFinal
  * @param type $codCentro
  * @return boolean|\PDOException
  * @throws PDOException
  */
 public static function newFicha($id, $programa, $fechaInicio, $fechaFinal, $codCentro)
 {
     try {
         $sql = "INSERT INTO ficha (num_ficha, cod_programa, fecha_ini, fecha_fin, cod_centro) VALUES ({$id}, '{$programa}', '{$fechaInicio}', '{$fechaFinal}', '{$codCentro}')";
         DataBaseClass::getCnx()->beginTransaction();
         $anwr = DataBaseClass::getCnx()->exec($sql);
         DataBaseClass::getCnx()->commit();
         if ($anwr !== false) {
             $anwr = true;
         } else {
             throw new PDOException("La Ficha {$id}, {$programa} ha sido REGISTRADA");
         }
         return $anwr;
     } catch (PDOException $e) {
         return $e;
     }
 }
 /**
  *  funcion para registrar una causa desercion
  * @param type $id
  * @param type $desc
  * @param type $estado
  * @return boolean|\PDOException
  * @throws PDOException
  */
 public static function newCausaDesercion($id, $desc, $estado)
 {
     try {
         $sql = "INSERT INTO causa_desercion (cod_causa, desc_causa, estado) VALUES (" . $id . ", '{$desc}', '{$estado}')";
         DataBaseClass::getCnx()->beginTransaction();
         $anwr = DataBaseClass::getCnx()->exec($sql);
         DataBaseClass::getCnx()->commit();
         if ($anwr !== false) {
             $anwr = true;
         } else {
             throw new PDOException("La causa de desercion {$id}, {$desc} {$estado} ya ha sido REGISTRADA");
         }
         return $anwr;
     } catch (PDOException $e) {
         return $e;
     }
 }
 /**
  * 
  * @param type $id
  * @param type $idApre
  * @param type $estado
  * @return boolean|\PDOException
  * @throws PDOException
  */
 public static function newMatricula($id, $idApre, $estado)
 {
     try {
         $sql = "INSERT INTO matricula (num_ficha, id_apre, estado) VALUES (" . $id . ", '{$idApre}', '{$estado}')";
         DataBaseClass::getCnx()->beginTransaction();
         $anwr = DataBaseClass::getCnx()->exec($sql);
         DataBaseClass::getCnx()->commit();
         if ($anwr !== false) {
             $anwr = true;
         } else {
             throw new PDOException("la matricula {$id}, {$idApre} {$estado} ya ha sido REGISTRADA");
         }
         return $anwr;
     } catch (PDOException $e) {
         return $e;
     }
 }
 /**
  *  funcion para registrar un rh
  * @param type $id
  * @param type $desc
  * @return boolean|\PDOException
  * @throws PDOException
  */
 public static function newRh($id, $desc)
 {
     try {
         $sql = "INSERT INTO rh (cod_rh, desc_rh) VALUES (" . $id . ", '{$desc}')";
         DataBaseClass::getCnx()->beginTransaction();
         $anwr = DataBaseClass::getCnx()->exec($sql);
         DataBaseClass::getCnx()->commit();
         if ($anwr !== false) {
             $anwr = true;
         } else {
             throw new PDOException("El rh {$id}, {$desc} ya han sido REGISTRADOS");
         }
         return $anwr;
     } catch (PDOException $e) {
         return $e;
     }
 }
 /**
  * 
  * @param type $id
  * @param type $nom
  * @param type $codDepto
  * @return boolean|\PDOException
  * @throws PDOException
  */
 public static function newCiudad($id, $nom, $codDepto, $habitantes)
 {
     try {
         $sql = "INSERT INTO ciudad (cod_ciudad, nom_ciudad, cod_depto, habitantes) VALUES ('{$id}' , '{$nom}', '{$codDepto}', '{$habitantes}')";
         //echo $sql;
         //die();
         DataBaseClass::getCnx()->beginTransaction();
         $anwr = DataBaseClass::getCnx()->exec($sql);
         DataBaseClass::getCnx()->commit();
         if ($anwr !== false) {
             $anwr = true;
         } else {
             throw new PDOException("La ciudad  {$id}, {$nom} ya ha sido REGISTRADA");
         }
         return $anwr;
     } catch (PDOException $e) {
         return $e;
     }
 }
 /**
  *
  * @param type $id
  * @param type $data
  * @return boolean|\PDOException
  * @throws PDOException
  */
 public static function updateMatricula($id, $data)
 {
     try {
         $sql = "UPDATE matricula SET ";
         foreach ($data as $key => $value) {
             $sql = $sql . " " . $key . " = '" . $value . "', ";
         }
         $newLeng = strlen($sql) - 2;
         $sql = substr($sql, 0, $newLeng);
         $sql = $sql . " WHERE num_ficha = " . $id;
         dataBaseClass::getCnx()->beginTransaction();
         $rsp = dataBaseClass::getCnx()->exec($sql);
         dataBaseClass::getCnx()->commit();
         if ($rsp !== false) {
             $rsp = true;
         } else {
             throw new PDOException("La Matricula no ha podido ser actualizado");
         }
         return $rsp;
     } catch (PDOException $e) {
         DataBaseClass::getCnx()->rollBack();
         return $e;
     }
 }
<?php

require_once 'DataBaseClass.php';
$num_ficha = $_POST['numficha'];
$idapre = $_POST['idapre'];
$estado = $_POST['estado'];
$sql = "INSERT INTO matricula" . "(num_ficha, id_apre, estado) " . "VALUES ('{$num_ficha}','{$idapre}','{$estado}')";
try {
    $objDB = new DataBaseClass('localhost', 'desercion', 'root', '');
    $objDB->getInstance()->beginTransaction();
    $objDB->getInstance()->exec($sql);
    $objDB->getInstance()->commit();
    echo "<PRE>";
    echo "Se Subieron los Campos: " . "<br>" . "Numero de Ficha: " . $num_ficha . "<br>" . "Codigo de Aprendiz: " . $idapre . "<br>" . "Estado: " . $estado;
    echo "</PRE>";
} catch (PDOException $ex) {
    $objDB->getInstance()->rollback();
    if ($ex->getCode() == 23000) {
        echo 'UNO DE LOS DATOS ESTA DUPLICADO';
    } else {
        echo $ex->getMessage();
    }
}
 public static function updateTid($id, $data)
 {
     try {
         $sql = "UPDATE tipo_id SET ";
         foreach ($data as $key => $value) {
             $sql = $sql . " " . $key . " = '" . $value . "', ";
         }
         $newLeng = strlen($sql) - 2;
         $sql = substr($sql, 0, $newLeng);
         $sql = $sql . " WHERE cod_tip_id = " . $id;
         dataBaseClass::getCnx()->beginTransaction();
         $rsp = dataBaseClass::getCnx()->exec($sql);
         dataBaseClass::getCnx()->commit();
         if ($rsp !== false) {
             $rsp = true;
         } else {
             throw new PDOException("El tipo de Identificacion {$id} no ha podido ser actualizado");
         }
         return $rsp;
     } catch (PDOException $e) {
         DataBaseClass::getCnx()->rollBack();
         return $e;
     }
 }
        <title>Insertar Registros</title>
        <style type="text/css">
            <!--
            body {
                background-color: #00BFFF;
            }
            body,td,th {
                color: #0B3B17;
            }
            -->
        </style></head>
<?php 
require_once 'DataBaseClass.php';
$cod_ciudad = $_POST['cod_ciudad'];
try {
    $objDB = new DataBaseClass('localhost', 'desercion', 'root', '');
    $sql = "SELECT * from ciudad where cod_ciudad='{$cod_ciudad}'";
    $arrData = $objDB->getInstance()->query($sql)->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOExcepcion $ex) {
    echo $exc->getmessage();
}
?>
<html>
    <head>
        <title>Campos a Eliminar</title>
    </head>
    <body>
        <form name="datos" method="post" action="delCiudad.php">
            <div align="center">
                <table border="1">
                    <tr>
 /**
  *  funcion para registrar un aprendiz
  * @param type $id
  * @param type $nombre
  * @param type $apellido
  * @param type $telefono
  * @param type $codciudad
  * @param type $codrh
  * @param type $codtipid
  * @param type $genero
  * @param type $edad
  * @return boolean|\PDOException
  * @throws PDOException
  */
 public static function newAprendiz($id, $nombre, $apellido, $telefono, $codciudad, $codrh, $codtipid, $genero, $edad)
 {
     try {
         $sql = "INSERT INTO aprendiz (id_apre, nom_apre, apell_apre, tel_apre, cod_ciudad, cod_rh, cod_tipo_id, genero, edad) VALUES (" . $id . ", '{$nombre}', '{$apellido}', {$telefono}, {$codciudad}, {$codrh}, {$codtipid}, '{$genero}', {$edad})";
         DataBaseClass::getCnx()->beginTransaction();
         $anwr = DataBaseClass::getCnx()->exec($sql);
         DataBaseClass::getCnx()->commit();
         if ($anwr !== false) {
             $anwr = true;
         } else {
             throw new PDOException("This student {$id}, {$nombre} {$apellido} has already been REGISTERED");
         }
         return $anwr;
     } catch (PDOException $e) {
         return $e;
     }
 }
 public static function updateDatUser($id, $data)
 {
     try {
         $sql = "UPDATE Datos_usuario SET ";
         foreach ($data as $key => $value) {
             $sql = $sql . " " . $key . " = '" . $value . "', ";
         }
         $newLeng = strlen($sql) - 2;
         $sql = substr($sql, 0, $newLeng);
         $sql = $sql . " WHERE id = " . $id;
         dataBaseClass::getCnx()->beginTransaction();
         $rsp = dataBaseClass::getCnx()->exec($sql);
         dataBaseClass::getCnx()->commit();
         if ($rsp !== false) {
             $rsp = true;
         } else {
             throw new PDOException("Los Datos Del Usuario no han podido ser actualizado", 2632);
         }
         return $rsp;
     } catch (PDOException $e) {
         DataBaseClass::getCnx()->rollBack();
         return $e;
     }
 }