1
Guys this Class is giving me a work I confess to you that I see no error here, I have seen in php.net I believe that I am following all the logics and syntax. If anyone can help me solve this problem I am very grateful.
<?php
include_once 'Conexao.class.php';
class Administrador {
private $Nome;
private $Endereco;
private $Telefone;
private $Conn;
public function __construct() {
$this->Conn = new Conexao();
}
public function inserir($Nome, $Endereco, $Telefone){
$sql = "INSERT INTO CADPES (NOME, ENDERECO, NUMERO)VALUES(?,?,?)";
$params = array($this->Nome, $this->Endereco, $this->Telefone);
$query = sqlsrv_query($this->Conn->Conectar(), $sql, $params) or die( print_r( sqlsrv_errors(), true));
}
}
Adm class and now my Connected class
<?php
class Conexao{
private $Localhost = 'NOTEBOOK101010\SQLEXPRESS';
private $User = 'sa';
private $Pass = '';
private $Database = 'ALISON';
private $Con = null;
private $Coninfo = null;
function __construct() {
//return $this->Coninfo;
}
public function Conectar(){
$this->Localhost;
$this->User;
$this->Pass;
$this->Database;
$this->Con = array("Database" => $this->Localhost, "UID" => $this->User, "PWD" => $this->Pass);
$this->Coninfo = sqlsrv_connect($this->Database, $this->Con);
return $this->Coninfo;
if($this->Coninfo){
echo "Conectou";
}else{
die(print_r(sqlsrv_error(), true));
}
}
}
?>
I changed the Return as you said I put it in the condition if now it brings another error +/ vc had already given the hint. But how do I fix it? sqlsrv_query() expects Parameter 1 to be Resource, null Given in
– Alison Paulo
In fact you have to put something like "echo $this->Coninfo;" then a var_dump(sqlsrv_errors();die; to see what is returning in Conifo and if there was an error. From there you see what needs to change for your connection to work
– Guerra