Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. <?php
  2. class Database
  3. {
  4. // private static $dbName = 'naw' ;
  5. private static $dbName = 'naw';
  6. // private static $dbHost = 'localhost' ;
  7. private static $dbHost = 'localhost' ;
  8. // private static $dbUsername = 'root';
  9. private static $dbUsername = 'root';
  10. // private static $dbUserPassword = '';
  11. private static $dbUserPassword = '';
  12.  
  13. private static $cont = null;
  14.  
  15.  
  16. public static function connect()
  17. {
  18. // One connection through whole application
  19. if ( null == self::$cont )
  20. {
  21. try
  22. {
  23. self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
  24. }
  25. catch(PDOException $e)
  26. {
  27. die($e->getMessage());
  28. }
  29. }
  30. return self::$cont;
  31. }
  32.  
  33. public static function query($query) {
  34. try {
  35.  
  36. $q = self::$cont->prepare($query);
  37. $q->execute();
  38.  
  39. $data = $q->fetchAll();
  40.  
  41. } catch (PDOException $e) {
  42. echo $e;
  43. }
  44. return $data;
  45. }
  46.  
  47.  
  48.  
  49. public static function disconnect()
  50. {
  51. self::$cont = null;
  52. }
  53. }
  54. ?>
  55.  
  56. <?php
  57. require_once '../php/conector.php';
  58.  
  59. $id = $_POST['id'];
  60. $nombre = $_POST['nombre'];
  61. $telefono = $_POST['telefono'];
  62. $correo = $_POST['correo'];
  63. $comuna = $_POST['comuna'];
  64. $actualizado = $_POST['actualizado'];
  65.  
  66.  
  67. // function update_modal() {
  68. try {
  69. $pdo = new Database;
  70. $pdo->connect();
  71. $sql = "UPDATE `menmbresia`
  72. SET `nombre_apellido` = $nombre ,
  73. `telefono` = $telefono ,
  74. `correo` = $correo ,
  75. `comuna` = $comuna ,
  76. `actualizado` = $actualizado,
  77. WHERE id ='{$id}'";
  78. try {
  79. $w = $pdo->update($sql);
  80. } catch (PDOExecption $e) {
  81. $pdo->rollback();
  82. }
  83. } catch ( PDOExecption $e) {
  84. }
  85. // database::disconnect();
  86. $pdo->disconnect();
  87. return;
  88. // }
  89.  
  90. ?>
  91.  
  92. public static function update($sql) {
  93. try {
  94.  
  95. $q = self::$cont->prepare($sql);
  96. $q->execute();
  97.  
  98. } catch (PDOException $e) {
  99. echo $e;
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement