note 114791 deleted from pdo.construct by cmb

From: Date: Mon, 28 Sep 2020 13:28:25 +0000
Subject: note 114791 deleted from pdo.construct by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215479@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- To connect to the database via a function use this and call the getConnection function in the class constructor. <?php class Connection{ protected $db; public function Connection(){ $conn = NULL; try{ $conn = new PDO("mysql:host=localhost;dbname=dbname", "dbuser", "dbpass"); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e){ echo 'ERROR: ' . $e->getMessage(); } $this->db = $conn; } public function getConnection(){ return $this->db; } } ?>

« previous php.notes (#215479) next »