PHP - Error mysql_connect(): The mysql extension is deprecated and will be removed

 
Vista:
sin imagen de perfil
Val: 15
Ha aumentado su posición en 12 puestos en PHP (en relación al último mes)
Gráfica de PHP

Error mysql_connect(): The mysql extension is deprecated and will be removed

Publicado por Jose luis (9 intervenciones) el 01/06/2016 16:14:27
Hola Buenas tardes ,

Una gran duda que me trae de cabeza , estoy mudando de un servidor a un Hosting nuevo y al Instalar la programación de nuevo me tira el error .

mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO insteadNon-static method Config::instance()

Leyendo por la red ,pero no consigo corregir el error la programación es eSyndiCat Directory que las Utilizo para una modesta web recetas de cocina desde el 2007 .

Cualquier ayuda me seria de gran ayuda gracias . Un saludo

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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<?php
/***************************************************************************
 *
 *
 *
 *   Link to eSyndiCat.com can not be removed from the software pages without
 *	 permission of eSyndiCat respective owners. It is the only requirement
 *	 for using this software.
 *
 *   Copyright 2005-2007 Intelliants LLC
 *   http://www.intelliants.com/
 *
 ***************************************************************************
 *
 *	 Implements class needed for work with database
 *
 ***************************************************************************/
 
class Database
{
	var $mConfig;
	var $mLink = null;
 
	// specific for every derived class
	var $mTable = '';
 
	// used in resetTable and setTable methods
	var $_tableNameBackup = '';
 
	/**
	* Connects to database
	*/
	function connect()
	{
		$this->mLink = mysql_connect($this->mConfig['dbhost'].":".$this->mConfig['dbport'], $this->mConfig['dbuser'], $this->mConfig['dbpass']);
		if (!$this->mLink)
		{
			if(DEBUG == 0)
			{
				$msg = "Could not connect";
			}
			else
			{
				$msg = "Could not connect to the database. For more information see error logs";
			}
			die($msg);
		}
 
		if(MYSQLVER > 40)
		{
			$this->query("SET NAMES 'utf8'");
		}
		if (!mysql_select_db($this->mConfig['dbname'],$this->mLink))
		{
			trigger_error("An error occured while selecting database: ".mysql_error($this->mLink), E_USER_ERROR);
			die ();
		}
	}
 
	/**
	* Used to set table to work with (almost always resetTable should be called after calling this method)
	*
	* @param str $tablename
	* @param str $prefix with or without prefix
	*
	* @return string
	*/
	function setTable($tablename,$prefix=true)
	{
		// store for further usage in resetTable
		$this->_tableNameBackup = $this->mTable;
		if($prefix)
		{
			$this->mTable = $this->mPrefix.$tablename;
		}
		else
		{
			$this->mTable = $tablename;
		}
	}
 
	/**
	* Reset previously changed table
	*/
	function resetTable()
	{
		if(empty($this->_tableNameBackup))
		{
			return false;
		}
		// store for further usage in resetTable
		$this->mTable = $this->_tableNameBackup;
		$this->_tableNameBackup = '';
	}
 
	/**
	* Executes sql query
	*
	* @param str $aSql sql query
	*
	* @return bool
	*/
	function query($aSql)
	{
		if(!$this->mLink)
		{
			$this->connect();
		}
		if(DEBUG===2)
		{
			$t = Debug::m();
		}
		$rs = mysql_query($aSql, $this->mLink);
		if(DEBUG===2)
		{
			$t = round(Debug::m() - $t,4);
			$t = "DB Query: |".$t." ".$aSql;
			trigger_error($t, E_USER_NOTICE);
		}
 
		if (!$rs)
		{
			$error = mysql_error();
 
			$esynConfig = new Config();
 
			$config = & $esynConfig->instance();
			$email = $config->get('bugs_email');
			if ($email)
			{
				$event 	= array(
				"type"		=> EMAIL_NOTIFY,
				"action" 	=> "site_error",
				"params" 	=> array(
					"rcpts"		=>	array($email),
					"subject"	=> " [database error]",
					"body"		=> "SQL Server's error: ".$error."\n \n SQL Query: ".$aSql
					)
				);
				//$config->notify($event);
			}
 
			ob_start();
			echo '<div style="border: 1px solid #F00; font: 12px verdana; width: 500px; margin: 0 auto; color: #F00; background-color: #EFEFEF; clear: both;font-weight:bold;">';
			echo "<div style=\"border-bottom: 1px solid #F00; padding: 10px;\"><strong>Error:</strong> ".$error."</div>";
			echo "<div style=\"background-color: #EAEAEA; padding: 10px;\">".$aSql."</div>";
			echo '</div>';
 
			echo "<PRE style=\"color:red;background-color:white;padding:5px;font-size:16px;font-weight:bold;\">";
			echo "\n\n<h3>Debug backtrace:</h3>\n";
			debug_print_backtrace();
			echo "<hr />";
			echo "</PRE>";
			$data = ob_get_clean();
			if(DEBUG)
			{
				echo $data;
			}
			trigger_error("Database query error: ".strip_tags($data), E_USER_ERROR);
			die("Fatal database error");
		}
 
		return $rs;
	}
 
	/**
	* Returns row of elements
	*
	* @param str $aSql sql query
	*
	* @return arr
	*/
	function getRow($aSql)
	{
		$out	= false;
		$r		= $this->query($aSql);
		if($this->getNumRows($r) > 0)
		{
			$out = mysql_fetch_assoc($r);
		}
 
		return $out;
	}
 
	/**
	* Returns array of rows
	*
	* @param str $aSql sql query
	*
	* @return arr|FALSE
	*/
	function getAll($aSql)
	{
		$out = false;
 
		$r = $this->query($aSql);
		if($this->getNumRows($r) > 0)
		{
			$out = array();
			while($temp = mysql_fetch_assoc($r))
			{
				$out[] = $temp;
			}
			return $out;
		}
	}
 
	/**
	* Returns recordset as associative array where the key is the first field
	*
	* @param str $aSql sql query
	*
	* @return arr
	*/
	function getAssoc($aSql)
	{
		$out = false;
		$r = $this->query($aSql);
		if($this->getNumRows($r))
		{
			$out = array();
			while ($temp = mysql_fetch_assoc($r))
			{
				$key = array_shift($temp);
				$out[$key][] = $temp;
			}
		}
 
		return $out;
	}
 
	/**
	* Returns recordset as associative array where the key is the first field
	*
	* @param str $aSql sql query
	*
	* @return arr
	*/
	function getKeyValue($aSql)
	{
		$out = false;
		$r = $this->query($aSql);
		if($this->getNumRows($r) > 0)
		{
			$out = array();
			while ($temp = mysql_fetch_row($r))
			{
				$out[$temp[0]] = $temp[1];
			}
		}
		return $out;
	}
 
	/**
	* Returns only one element or false!
	*
	* @param str $aSql sql query
	*
	* @return string
	*/
	function getOne($aSql)
	{
		$ret = false;
		$r = $this->query($aSql);
		if($this->getNumRows($r) > 0)
		{
			$ret = mysql_result($r,0,0);
		}
		return $ret;
	}
 
	/**
	* Returns true if at least 1 record exists
	*
	* @param str $aSql sql query
	*
	* @return bool
	*/
	function exists($aSql)
	{
		$r = $this->query($aSql);
		return $this->getNumRows($r) > 0;
	}
 
	function getInsertId()
	{
		return mysql_insert_id($this->mLink);
	}
 
	function getAffected()
	{
		return mysql_affected_rows($this->mLink);
	}
 
	function getNumRows($rs)
	{
		return mysql_num_rows($rs);
	}
 
	/**
	* Returns found rows of previous DQL with SQL_CALC_FOUND_ROWS
	* Note: this SQL function is MySQL specific!
	*/
	function foundRows()
	{
		return (int)$this->getOne("SELECT FOUND_ROWS()");
	}
 
	/**
	* Close connection to database
	*
	* @param $aConnection connection
	*
	* return bool
	*/
	function close($aConn=null)
	{
		if(null==$aConn)
		{
			$aConn = $this->mLink;
		}
		return mysql_close($aConn);
	}
 
	/*
	* get's ID from the string like
	* "`id`='123'" or
	* "id='123'" or
	* "id=123" or
	* "`id`=123" (123 in this case) or
	* false
	*/
	function scanForId($str)
	{
		$id = false;
		if(preg_match("/\bid[^=]?\s*=\s*'?(\d+)/", $str, $m))
		{
			$id = (int)$m[1];
		}

		return $id;
	}

	function describe($table = false)
	{
		if(!$table)
		{
			$table = $this->mTable;
		}

		return $this->getAll("DESC `".$table."`");
	}
}
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
Imágen de perfil de kip
Val: 2.325
Plata
Ha disminuido 1 puesto en PHP (en relación al último mes)
Gráfica de PHP

Error mysql_connect(): The mysql extension is deprecated and will be removed

Publicado por kip (877 intervenciones) el 01/06/2016 17:53:14
Hola, la extension Mysql esta obsoleta y es ese el mensaje que te muestra, podrias desactivar aquel mensaje para que no te aparezca mas pero te recomiendo mejor usar Mysqli, es muy parecida pero debes pasarte por el manual de referencia y echarle un ojo a las funciones de aquella extension para diferenciar las funciones ambas.

1
http://php.net/manual/es/book.mysqli.php

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 15
Ha aumentado su posición en 12 puestos en PHP (en relación al último mes)
Gráfica de PHP

Error mysql_connect(): The mysql extension is deprecated and will be removed

Publicado por Jose luis (9 intervenciones) el 03/06/2016 11:46:22
Perdón por la tardar en responder kip y Muchas gracias por responder .

Mis conocimientos php y mysql son muy limitados , me podrías explicar que tendría que cambiar para que no me salga el error y que se adapte a Mysqli ?


Un saludo Gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar