Prueba así, después de
$this-> la variable va sin el simbolo
$<?php
class Conexion
{
public $ndatabase;
public function conectar()
{
$this->ndatabase = $_POST['cod_empresa'];
$server = 'stmbielve';
$database = $this->ndatabase;
$username = 'root';
$password = '';
return $conexion = new PDO('sqlsrv:Server=' . $server . ';Database='. $database, $username, $password);
//$this->dbh->exec("SET CHARACTER SET utf8");
}
}
?>
La línea que he comentando
//$this->dbh->exec("SET CHARACTER SET utf8");
si la pones después del
return nunca se va a ejecutar, de todas formas
$this->dbh no está declarado en ningún sitio.
En el php principal, pon:
$CONN = new Conexion;
$conexion = $CONN->conectar();