0
I searched many places and was amazed to find almost nothing of PHP OO using SQL Server. In short, I cannot understand what is wrong here, I think it helps, I thank you.
<?php
class Conexao{
private $Localhost = 'NOTEBOOK101010\SQLEXPRESS';
private $User = 'sa';
private $Pass = '';
private $Database = 'ALISON';
private $Con = null;
private $Coninfo = null;
function __construct() {
$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->Con, $this->Database);
if($this->Coninfo){
echo "Conectou";
return true;
}else{
die(print_r(sqlsrv_error(), true));
}
}
}
?>
This is my Connection class following my Administrator class
<?php
include_once 'Conexao.class.php';
class Administrador {
private $Nome;
private $Endereco;
private $Telefone;
private $Con;
public function __construct() {
$this->Con = new Conexao();
}
public function inserir($Nome, $Endereco, $Telefone){
$sql = "INSERT INTO CADPES (NOME, ENDERECO, NUMERO)VALUES($this->Nome, $this->Endereco, $this->Telefone)";
$query = sqlsrv_query($this->Con->Conectar(), $sql);
}
}
I wish I knew where I was going wrong !
Puts the full error message in the question.
– rray
missing a
return
after that line$this->Coninfo = sqlsrv_connect($this->Con, $this->Database);
ie, Return$this->Coninfo;
if everything is all right miss this. Also has design problems plus this is another story– novic
Did not resolve =( this is the Catchable fatal error: Argument 2 passed to sqlsrv_connect() must be of the type array, string Given, called in
– Alison Paulo