I'm trying to connect SQLServer 2014 with PHP, when trying this code works
$servidor = "NOMBREPC\SQLEXPRESS";
$database = "PRUEBA";
$info = array('Database'=>$database);
$cn = sqlsrv_connect($servidor, $info);
But when trying using a class, it does not work
class Conexion{
public function conectar(){
$servidor = "NOMBREPC\SQLEXPRESS";
$database = "PRUEBA";
$info = array('Database'=>$database);
$cn = sqlsrv_connect($servidor, $info);
}
}
I do not know what the error is, it should be noted that in the first block of code use an if to know if it connected, but in the second when trying it does not show the message, also try with the die ().
Please help me. T.T
EDITING
In the first example if you use the sqlsrv_errors , when I changed a value that was not correct, the errors came out, but in the second I put an if, if I connected, I had to leave connected but nothing comes out, the screen goes blank. The code to call use the following:
include ("Conexion.php");
class MiClase{
public function miFuncion(){
$cn = new Conexion;
$cn->conectar();
}
}
I still can not connect using the class.