Guest User

Untitled

a guest
Aug 4th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. *
  5. */
  6. class NotaMatic {
  7.  
  8. //el constructor siempre se ejecuta atomaticamente
  9.  
  10. public $host = "localhost:8888";
  11. public $username = "root";
  12. public $password = "root";
  13.  
  14. function __construct() {
  15.  
  16. mysql_connect( "localhost:8888", "root", "root" );
  17.  
  18. mysql_select_db("pcm5");
  19.  
  20. }
  21.  
  22. function test(){
  23. return "hola mundo";
  24. }
  25.  
  26. function insertAlumno($nombre, $apellido, $curso){
  27.  
  28. $sql = "INSERT INTO alumnos (id, nombre, apellido, curso) VALUES ('','$nombre','$apellido','$curso')";
  29.  
  30. $resultado = mysql_query($sql) or die( "error" );
  31.  
  32. return $resultado;
  33. }
  34.  
  35. function getAlumnos(){
  36.  
  37. $sql = "SELECT * FROM alumnos ORDER BY id ASC";
  38.  
  39. $resultado = mysql_query($sql) or die("error");
  40.  
  41. $r= mysql_fetch_array($resultado);
  42.  
  43. return $r[0];
  44.  
  45. }
  46. //Ejercicio con nota: escribir los métodos necesarios para: insertarNota, getNota, borrarAlumno, borrarNota, actualizarAlumno y actualizarNota
  47.  
  48. function borrarAlumno($id){
  49.  
  50. $sql = "DELETE FROM alumnos WHERE id = '$id' ";
  51.  
  52. $resultado = mysql_query($sql) or die("error");
  53.  
  54. return ($resultado);
  55.  
  56. }
  57.  
  58. function actualizarAlumno($id, $nombre, $apellido, $curso){
  59.  
  60. $sql = "UPDATE alumnos SET nombre = '$nombre', apellido = '$apellido', curso = '$curso' WHERE id = '$id'";
  61.  
  62. $resultado = mysql_query($sql) or die("error");
  63.  
  64. return ($resultado);
  65.  
  66. }
  67.  
  68. function insertarNota($id_usuario, $descripcion, $nota){
  69.  
  70. $sql = "INSERT INTO notas (id, id_usuario, descripcion, nota) VALUES ('','$id_usuario','$descripcion','$nota')";
  71.  
  72. $resultado = mysql_query($sql) or die("error");
  73.  
  74. return ($resultado);
  75.  
  76. }
  77.  
  78. function getNota(){
  79.  
  80. $sql = "SELECT * FROM notas ORDER BY id ASC";
  81.  
  82. $resultado = mysql_query($sql) or die("error");
  83.  
  84. return mysql_fetch_array($resultado);
  85.  
  86. }
  87.  
  88. function borrarNota($id){
  89.  
  90. $sql = "DELETE FROM notas WHERE id = '$id' ";
  91.  
  92. $resultado = mysql_query($sql) or die("error");
  93.  
  94. return ($resultado);
  95.  
  96. }
  97.  
  98. function actualizarNota($id, $id_usuario, $descripcion, $nota){
  99.  
  100. $sql = "UPDATE notas SET id_usuario = '$id_usuario', descripcion = '$descripcion', nota = '$nota' WHERE id = '$id'";
  101.  
  102. $resultado = mysql_query($sql) or die("error");
  103.  
  104. return ($resultado);
  105.  
  106. }
  107.  
  108. }
  109.  
  110. ?>
Add Comment
Please, Sign In to add comment