Argument 2 passed to sqlsrv_connect () must be of the type array, string given

0

I searched in many places and was amazed to find almost nothing of PHP OO using SQL Server. In short, I can not understand what is wrong here, I think it helps, thank you in advance.

<?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 class Connection below my class Admin

<?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 wonder where I'm going wrong!

    
asked by anonymous 05.10.2016 / 22:12

1 answer

0

Passing of arguments is changed in sqlsrv_connect () function signature is

  

sqlsrv_connect (string $ serverName [ array $ connectionInfo])

Change:

$this->Coninfo = sqlsrv_connect($this->Con, $this->Database);

To:

$this->Coninfo = sqlsrv_connect($this->Database, $this->Con);
    
05.10.2016 / 22:27