A migration from Oracle to MySQL was recently done at my work, so when I change the connection to the DB in one of my projects it throws me errors when trying to log in.
The connection code is as follows:
class Target
{
public static function Conectar()
{
try
{
$conexion = new PDO('mysql:host=10.2.3.5;port=3306;dbname=BI_TGT;charset=UTF8','bi_tgt','password');
}
catch(Exception $e)
{
$e->getMessage();
}
return $conexion;
}
}
The login code is as follows:
require_once("conexion.php");
class Model
{
public static function ingresoUsuarioModel($datosModel, $tabla)
{
$stmt = Target::Conectar()->prepare("select ba, password, nombre from $tabla where ba = :usuario");
$stmt->bindParam(":usuario", $datosModel['usuario'], PDO::PARAM_STR);
$stmt->execute();
return $stmt->fetch(PDO::FETCH_ASSOC);
}
}
It throws me the following errors:
Notice : Undefined variable: connection Fatal error Uncaught Error:Call to a member function prepare() on null
The problem arises when trying to connect to the server where mysql is hosted because if I use the same code but with the connection to oracle it works perfect, the connection data to mysql is correct I don't know what is happening, I can't find the way to solve the problem, if anyone can help me it would be great.