Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)' in /var/www/html/funerariasaopedro.net.br/web/crud/_conexao/Conexao.php:33 Stack trace: #0 /var/www/html/funerariasaopedro.net.br/web/crud/_conexao/Conexao.php(33): PDO->__construct('mysql:?????????...', 'carcleo', 'teste') #1 /var/www/html/funerariasaopedro.net.br/web/crud/cadastraPlanos.php(9): CONEXAOConexao->__construct() #2 /var/www/html/funerariasaopedro.net.br/web/crud/index.php(27): require_once('/var/www/html/f...') #3 {main} thrown in /var/www/html/funerariasaopedro.net.br/web/crud/_conexao/Conexao.php on line 33
- <?php
- namespace CONEXAO;
- use PDO;
- class Conexao {
- private static $conexao;
- private static $hostname = "server";
- private static $dbname = "banco";
- private static $username = "user";
- private static $password = "password";
- public function __construct() {
- if (isset(self::$conexao)) {
- self::$conexao = self::$conexao;
- } else {
- try {
- self::$conexao = new PDO('mysql:
- host='.self::$hostname.';
- dbname='.self::$dbname,
- self::$username,
- self::$password
- );
- } catch (Exception $e) {
- self::$conexao = NULL;
- echo $e->getMessage();
- }
- }
- }
- public function abreConexao() {
- return self::$conexao;
- }
- public function fechaConexao () {
- if (self::$conexao != null) {
- self::$conexao = null;
- }
- }
- }
Add Comment
Please, Sign In to add comment