Saltar al contenido
Codifíca.me | Desarrollo web | Programación

[Solución] Opencart | Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in mysql.php on line 6

18 mayo, 2016

Rescato la solución a este problema que surge cuando cambias de versión de Php en tu servidor y trabajas con alguna versión antigua de Opencart.

Opencart
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in mysql.php on line 6

Para resolverlo, subir el siguiente código al directorio system/database de tu instalación de Opencart

El fichero se llamará mmysqli.php , quedaría así:

/system/database/mmysqli.php

Modificar los ficheros config.php y admin/config.php

Opencar solucion

Cambiar el driver que vas a utilizar, tendréis que cambiar esta linea:

define(‘DB_DRIVER’, ‘mysqli’);

Por el driver que acabamos de subir mmysqli:

define(‘DB_DRIVER’, ‘mmysqli’);

<?php
final class mMySQLi {
	private $link;
 
	public function __construct($hostname, $username, $password, $database) {
		$this->link = new mysqli($hostname, $username, $password, $database);
 
		if ($this->link->connect_error) {
			trigger_error('Error: Could not make a database link (' . $this->link->connect_errno . ') ' . $this->link->connect_error);
		}
 
		$this->link->set_charset("utf8");
		$this->link->query("SET SQL_MODE = ''");
	}
 
	public function query($sql) {
		$query = $this->link->query($sql);
 
		if (!$this->link->errno) {
			if ($query instanceof mysqli_result) {
				$data = array();
 
				while ($row = $query->fetch_assoc()) {
					$data[] = $row;
				}
 
				$result = new stdClass();
				$result->row = isset($data[0]) ? $data[0] : array();
				$result->rows = $data;
				$result->num_rows = $query->num_rows;
 
				$query->close();
 
				return $result;
			} else {
				return true;
			}
		} else {
			trigger_error('Error: ' . $this->link->error  . '<br />Error No: ' . $this->link->errno . '<br />' . $sql);
		}
	}
 
	public function escape($value) {
		return $this->link->real_escape_string($value);
	}
 
	public function countAffected() {
		return $this->link->affected_rows;
	}
 
	public function getLastId() {
		return $this->link->insert_id;
	}
 
	public function __destruct() {
		$this->link->close();
	}
}
?>

Y listo, solucionado 😉