PHP - Notice: Use of undefined constant CERRADA - assumed 'CERRADA' in ...

 
Vista:
sin imagen de perfil

Notice: Use of undefined constant CERRADA - assumed 'CERRADA' in ...

Publicado por DUVAN JOSE (1 intervención) el 12/02/2018 23:27:30
hola amigos quien pudiera ayudarme.

tengo este problema:

Notice: Use of undefined constant CERRADA - assumed 'CERRADA' in C:\xampp\htdocs\Proyecto_AJAX\DB.php on line 8

Notice: Undefined index: caracteres in C:\xampp\htdocs\Proyecto_AJAX\autocompleteloc.php on line 7

acá los código

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/*
Conexion a la base de datos

1. Iniciamos un objeto global a todos los PHP que lo incluyan
*/
$bd = new BD();
 
 
class BD{
 
	var $host="localhost";
	var $user = "root";
	var $password="";
	var $database = "proyectoajax";
	var $conn;
 
	const ABIERTA = 1;
	const CERRADA = 0;
 
	var $status = CERRADA;
 
	/*Abre la base de datos*/
 
	public function open(){
		$this->conn = mysql_connect($this->host,$this->user,$this->password) or die (mysql_error());
		mysql_select_db($this->database, $this->conn) or die (mysql_error());
 
	}
	/*

	Cierra la base de datos

	*/
	public function close(){
		mysql_close($this->$conn);
	}
 
 
	/*

	Ejecuta una consulta que no devuelve resultados
	@param string $sql Consulta SQL

	*/
 
	public function ExecuteNonQuery($sql){
 
		if ($this->status==BD::CERRADA) $this->open();
		$rs = mysql_query($sql, $this->conn);
		settype($rs, "null");
 
	}
 
 
	/*

	Ejecuta una consulta SQL

	@param string $query COnsulta SQL
	@return un array de registros, cada uno siendo un array asociativo de campos
	*/
 
	public function Execute($query){
		if ($this->status == BD:: CERRADA) $this->open();
 
		$rs = mysql_query($query, $this->conn);
 
		// paso el  recordset a array asociativo
		$registros  = array();
 
		while ($reg=mysql_fetch_array($rs)){
			$registros[] = $reg;
		}
 
		return $registros;
	}
 
	/*
	Ejecuta una consulta devolviendo una fila (registro) con todos sus campos

	@param string $tableName NOmbre de la tabla
	@param string $filter filtro SQL para el where
	@return un array asociativo de campos
	*/
 
	public function ExecuteRecord($tableName, $filter){
		$todos = $this->Execute("SELECT * FROM $tableName WHERE $filter");
 
		return $todos[0];
	}
 
    /*

	Ejecuta uan consulta devolviendo una columna (campo) con todos sus registros

	@param string $tableName Nombre de la tabla
	@param strin $fiel Nombre del campo a traer
	@filtro Filtro del where (por lo menos debe ser 1=1)
	@return un array asociativo de valores de cada registro
    */
 
    public function ExecuteField($tableName, $field, $filter){
    	$todos = $this->Execute("SELECT $field FROM $tableName WHERE $filter");
    	$aux = array();
    	foreach ($todos as $uno){
    		$aux[] = $uno[0];
    	}
 
    	return $aux;
    }
 
	/*
	Trae todos los registros de una tabla

	@param string $tableName Nombre de la tabla
	@param string $orden Campo por el cual ordena (Opcional)
	@return un array de resgistros, cada uno un array asociativos

	*/
 
 
	public function ExecuteTable($tableName, $orden=""){
		if ($orden!="")
			return $this->Execute("SELECT * FROM". $tableName . "ORDER BY" . $orden);
		else
			return $this->Execute("SELECT * FROM" .$tableName);
	}
 
 
	/* Trae un solo valor de la base de datos

		@param string $query Consulta SQL (1x1)
		@return el valor devuelto por la consulta

	*/
 
	public function ExecuteScalar ($query){
		if ($this->status==BD::CERRADA) $this->open();
 
			$rs = mysql_query($query, $this->conn) or die (mysql_error());
			$reg = mysql_fetch_array($rs);
			return $reg[0];
 
	}
 
	/*

		Devuelve la cantidad de registros de una tabla
		@param string $tableName Nombre de la tabla
		@return Cantidad de Registros

	*/
 
	public function RecordCount($tableName){
		return $this->ExecuteScalar("SELECT COUNT(*) FROM " . $tableName);
	}
 
 
 
}
 
?>



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
<?php
 
/*Autocomplete localidades*/
 
include("DB.php");
 
$caracteres = $_POST["caracteres"];
 
if ($caracteres != ""){
	// lleva el nombre de la tabla, el campo y la instruccion where
 
	$aLocalidades = $bd->ExecuteField("USUARIIOS", "localidad", " localidad like '%%$caracteres%%' ");
 
	$respuesta = "<ul>";
 
	foreach ($aLocalidades as $localidad) {
		// le llevamos concatenado a la respuesta cada opcion
		$respuesta .="<li>". $localidad . "</li>";
	}
 
	$respuesta .= "</ul>";
 
	echo $respuesta;
}
 
 
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder