Guest User

Untitled

a guest
Jun 24th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <?php
  2. class Conexion{
  3.  
  4. protected $conexion_db;
  5.  
  6. public function Conectar()
  7. {
  8. try{
  9.  
  10. $this->conexion_db= new PDO('mysql:host=localhost; dbname=bd_espamep','root','123456');
  11. $this->conexion_db-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12. $this->conexion_db->exec("SET CHARACTER SET utf8"):
  13.  
  14. return $this->conexion_db;
  15.  
  16.  
  17.  
  18.  
  19.  
  20. }
  21. catch(PDOException $e){
  22. echo "La linea de error es: " . $e->getline();
  23. }
  24. }
  25. public function desconectar()
  26. {
  27. $this -> conexion = null;
  28. }
  29. }
  30. ?>
  31.  
  32. Negocios
  33.  
  34. <?php
  35. require_once "../Conexion/CapaDatos.php";
  36.  
  37. class Unidad extends Conexion
  38. {
  39.  
  40. public function CapaNegocios()
  41. {
  42. parent::__construct();
  43. }
  44.  
  45. public function InsertarUnidad($idempresa, $uni_nombre, $uni_objetivo, $uni_logo, $uni_eliminado)
  46. {
  47. try
  48. {
  49. $sql = "INSERT INTO unidad(idempresa, uni_nombre, uni_objetivo, uni_logo, uni_eliminado) VALUES (?,?,?,?,?)";
  50. $sentencia = $this->conexion_db->prepare($sql);
  51. $sentencia -> bind_param('isssi',$uni_nombre,$uni_objetivo, $uni_logo);
  52.  
  53. $sentencia->execute();
  54.  
  55. echo "Guardado";
  56.  
  57. }catch(Exception $e){
  58. echo $e->getMessage();
  59. }
  60. }
  61.  
  62.  
  63.  
  64. }
  65.  
  66. ?>
  67.  
  68. <?php
  69. require_once "../negocios/CapaNegocios.php";
  70.  
  71.  
  72. try{
  73. if(!empty($_POST))
  74. {
  75. $idempresa = 1;
  76. $uni_eliminado = 1;
  77. $uni_nombre = $_POST['txtunidad'];
  78. $uni_objetivo = $_POST['txtobjetivou'];
  79. $uni_logo = $_POST['logou'];
  80.  
  81. $objetoNegocio= new Unidad();
  82.  
  83. if(isset($_POST["Guardar"]))
  84. {
  85. $objetoNegocio-> InsertarUnidad($idempresa, $uni_nombre, $uni_objetivo, $uni_logo, $uni_eliminado);
  86. }
  87. }
  88. }
  89. catch(PD0Eception $e)
  90. {
  91. echo $e -> getMessage();
  92. }
  93.  
  94. ?>
Add Comment
Please, Sign In to add comment