1<?php
2class Connection
3{
4 protected $link;
5 private $dsn, $username, $password;
6
7 public function __construct($dsn, $username, $password)
8 {
9 $this->dsn = $dsn;
10 $this->username = $username;
11 $this->password = $password;
12 $this->connect();
13 }
14
15 private function connect()
16 {
17 $this->link = new PDO($this->dsn, $this->username, $this->password);
18 }
19
20 public function __sleep()
21 {
22 return array('dsn', 'username', 'password');
23 }
24
25 public function __wakeup()
26 {
27 $this->connect();
28 }
29}?>
1PHP stands for Hypertext Preprocessor.
2It is an open source server-side scripting language which is widely used for web development.
3It supports many databases like MySQL, Oracle, Sybase, Solid, PostgreSQL, generic ODBC etc.
1// Example usage for: Ternary Operator
2$action = $_POST['action'] ?: 'default';
3
4// The above is identical to this if/else statement
5if (empty($_POST['action'])) {
6 $action = 'default';
7} else {
8 $action = $_POST['action'];
9}