Guest User

Untitled

a guest
Jun 18th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. 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
  2.  
  3. <?php
  4.  
  5. namespace CONEXAO;
  6.  
  7. use PDO;
  8.  
  9. class Conexao {
  10.  
  11. private static $conexao;
  12.  
  13.  
  14. private static $hostname = "server";
  15. private static $dbname = "banco";
  16. private static $username = "user";
  17. private static $password = "password";
  18.  
  19.  
  20. public function __construct() {
  21.  
  22. if (isset(self::$conexao)) {
  23.  
  24. self::$conexao = self::$conexao;
  25.  
  26. } else {
  27.  
  28.  
  29. try {
  30.  
  31. self::$conexao = new PDO('mysql:
  32. host='.self::$hostname.';
  33. dbname='.self::$dbname,
  34. self::$username,
  35. self::$password
  36. );
  37.  
  38. } catch (Exception $e) {
  39.  
  40. self::$conexao = NULL;
  41.  
  42. echo $e->getMessage();
  43.  
  44. }
  45.  
  46. }
  47.  
  48. }
  49.  
  50. public function abreConexao() {
  51.  
  52. return self::$conexao;
  53.  
  54. }
  55.  
  56.  
  57. public function fechaConexao () {
  58.  
  59. if (self::$conexao != null) {
  60.  
  61. self::$conexao = null;
  62.  
  63. }
  64.  
  65. }
  66.  
  67. }
Add Comment
Please, Sign In to add comment