Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php // class
- class Database {
- // connection parameters
- protected $dbtype = 'mysql';
- protected $dbport = 3306;
- protected $dbhost = 'localhost';
- protected $dbuser = 'root';
- protected $dbpass = 'rootpass';
- protected $dbname = 'classes';
- public function getpdo() {
- // Build connection string.
- $dsn = sprintf(
- "%s:host=%s;port=%s;dbname=%s",
- $this->dbtype,
- $this->dbhost,
- $this->dbport,
- $this->dbname
- ); // $dsn
- // Connect to database.
- $this->pdo = new PDO($dsn, $this->dbuser, $this->dbpass);
- if (!isset($this->pdo)) {die("PDO is not set!");}
- return $this->pdo;
- } // getpdo
- } // database
- // class ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement