I am trying to create a% statica % for classe
to mysql with conexão
but is giving error on the PDO
line
<?php
namespace CONEXAO;
use PDO;
class Conexao {
public static $conexao;
private $host = "localhost";
private $db = "funeraria2";
private $user = "root";
private $password = "mysql";
private function __construct() {
try {
self::$conexao = new PDO('mysql:
host="'.$this->host.'";
dbname="'.$this->db.'",
"'.$this->user.'",
"'.$this->password.'"
');
} catch (Exception $e) {
self::$conexao = NULL;
return self::$conexao;
echo $e->getMessage();
exit;
} finally {
return self::$conexao;
}
}
public function fechaConexao () {
if (self::$conexao != null) {
self::$conexao = null;
}
}
}
I'm using finally
as the editor of Dreamweaver
and it gives me an error in the line as pictured below but I can not see any errors!
Change:
<?phpini_set("display_errors",true);
ini_set("display_startup_erros",true);
error_reporting(E_ALL | E_NOTICE | E_STRICT);
namespace CONEXAO;
use PDO;
class Conexao {
private static final $conexao;
private static final $host = "localhost";
private static final $dbname = "dbname";
private static final $user = "user";
private static final $password = "password";
public function __construct() {}
public function abreConexao() {
try {
self::$conexao = new PDO('mysql:
host=self::$host;
dbname=self::$dbname',
self::$user,
self::$password
);
} catch (Exception $e) {
self::$conexao = NULL;
echo $e->getMessage();
}
}
public function fechaConexao () {
if (self::$conexao != null) {
self::$conexao = null;
}
}
}
use CONEXAO\Conexao;
$conexao = new Conexao;
$conexao->abreConexao();