-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsultasSql.php
105 lines (93 loc) · 3.2 KB
/
consultasSql.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
function obtenVideojuegos($conexion){
try{
$consulta= "SELECT * from videojuegos";
$stmt = $conexion->query($consulta);
return $stmt;
}catch(PDOException $e) {
$_SESSION['excepcion'] = $e->GetMessage();
header("Location: excepcion.php");
}
}
function obtenVideojuegoPorOID($conexion, $oidV){
try{
$consulta = "SELECT distinct nombrevideojuego from videojuegos where oid_v=:oid_v";
$stmt = $conexion->prepare($consulta);
$stmt->bindParam(':oid_v',$oidV);
$stmt->execute();
return $stmt->fetch();
}catch(PDOException $e){
$_SESSION['excepcion'] = $e->GetMessage();
header("Location: excepcion.php");
}
}
function obtenOID_V($conexion, $nombreVideojuego){
try{
$consulta = "SELECT distinct oid_v from videojuegos where nombrevideojuego=:nombrevideojuego";
$stmt = $conexion->prepare($consulta);
$stmt->bindParam(':nombrevideojuego',$nombreVideojuego);
$stmt->execute();
return $stmt->fetch();
}catch(PDOException $e){
$_SESSION['excepcion'] = $e->GetMessage();
header("Location: excepcion.php");
}
}
function consulta_paginada( $conn, $query, $pag_num, $pag_size ){
try {
$primera = ( $pag_num - 1 ) * $pag_size + 1;
$ultima = $pag_num * $pag_size;
$consulta_paginada =
"SELECT * FROM ( "
."SELECT ROWNUM RNUM, AUX.* FROM ( $query ) AUX "
."WHERE ROWNUM <= :ultima"
.") "
."WHERE RNUM >= :primera";
$stmt = $conn->prepare( $consulta_paginada );
$stmt->bindParam( ':primera', $primera );
$stmt->bindParam( ':ultima', $ultima );
$stmt->execute();
return $stmt;
}
catch ( PDOException $e ) {
$_SESSION['excepcion'] = $e->GetMessage();
header("Location: excepcion.php");
}
}
function total_consulta( $conn, $query ){
try {
$total_consulta = "SELECT COUNT(*) AS TOTAL FROM ($query)";
$stmt = $conn->query($total_consulta);
$result = $stmt->fetch();
$total = $result['TOTAL'];
return $total;
}
catch ( PDOException $e ) {
$_SESSION['excepcion'] = $e->GetMessage();
header("Location: excepcion.php");
}
}
function racha($conexion){
try{
$consulta="SELECT nombreVideojuego from (SELECT oid_v,max(oid_e) oid_E from estadisticas natural join partidos group by oid_v)
natural join estadisticas natural join videojuegos where racha > 5";
$stmt = $conexion->prepare($consulta);
$stmt->execute();
return $stmt;
}catch(PDOException $e){
$_SESSION['excepcion'] = $e->GetMessage();
header("Location: excepcion.php");
}
}
function ultimosResultados($conexion){
try{
$consulta="select * from partidos natural join videojuegos natural join estadisticas where rownum<=5 order by partidos.fechahora DESC";
$stmt = $conexion->prepare($consulta);
$stmt->execute();
return $stmt;
}catch(PDOException $e){
$_SESSION['excepcion'] = $e->GetMessage();
header("Location: excepcion.php");
}
}
?>