<?php class AcessoBD{ private $conn; private $host; private $dbname; private $username; private $password; public function __construct($dbname){ $this ->host="localhost"; $this ->dbname=$dbname; $this ->username="root"; $this ->password=""; $this ->setConn(); } private function setConn(){ try { $this ->conn = new PDO("mysql:host=".$this->host.";dbname=".$this->dbname, $this->username, $this->password); $this ->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo 'ERROR: ' . $e->getMessage(); } } public function select($sql,$parametros){ $stmt = $this ->conn->prepare($sql); $stmt->execute($parametros); return $stmt ->fetchAll(); } } ?>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter