note 124348 deleted from pdo.connections by cmb

From: Date: Mon, 28 Oct 2019 17:26:49 +0000
Subject: note 124348 deleted from pdo.connections by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212866@lists.php.net to get a copy of this message
Note Submitter: rntokira at gmail dot com ---- <?php namespace classes; use PDO; class Database { protected static $db; private function __construct($banco) { $db_host = 'localhost'; $db_nome = $banco; $db_usuario = 'root'; $db_senha = 'root'; $db_driver = 'mysql'; try { self::$db = new PDO("$db_driver:host=$db_host; dbname=$db_nome", $db_usuario, $db_senha); self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$db->exec('SET NAMES utf8'); } catch (\PDOException $e) { echo 'Error connecting to MySQL: ' . $e->getMessage(); die("Connection Error: " . $e->getMessage()); } } public static function connectionDB($banco) { if (!self::$db) { new Database($banco); } return self::$db; } }

« previous php.notes (#212866) next »