0
I’m trying to create a classe
Statica for conexão
at the mysql with PDO
but is making a mistake in the line of finally
<?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 the Dreamweaver
as editor of códigos
and it gives me an error in line as picture below but I can not see any error!
Altering:
<?php
ini_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();
What is the error? puts the message in the question.
– rray
return
in the catch having the Finally; 3) It makes less sense even if you givereturn
inside the builder.– Woss
So I made a change to the code and put it at the end of the question. I created an open functionConexao() just for that. Yes: still giving server error (500). But in the console gives Request URL: data:image/png;Base64,iVBORw0KGgoAAAANSUhEUgABNEAABECAAAACKI/xBAAAAAAnRSTlMAAAHaTzTgAAn9SURBVHgB7J1Rktu8EYRbKSV/cBEeZfcCOOh8fFAeyj8CLzqNh2dRnroTmFABYEar7UL8GDGUhc7rYagMjA... huge
– Carlos Rocha
What is your version of PHP? The
finally
was only included in version 5.5. Another thing, this request you cite is from an image, does not seem to be related to the problem.– bfavaretto
PHP Version 7.2.1
– Carlos Rocha
removed Finally and still giving ero 500. Code at the end of the question
– Carlos Rocha
You will need to check the server logs to see the error. Always gave 500? Or started with recent changes?
– Leite
Need to look at apache error log.
– rray
I sent one last correction at the end of the question. I think the problem is in the concatenation of variables in the call to PDO. each parameter is bounded pro '', it is 3 in all. but when I want to put a variable in place of the parameter gives error. Please. Take a look at me like I did at the end of the question
– Carlos Rocha
can see the script running at http://www.funerariasaopedro.net.br/crud/Conexao
– Carlos Rocha