Do you know anything about OOP ?
Class should contain fields and/or methods. You just surrounded a piece of code with class{}. It is not programming.
Read about OOP in PHP - here is manual: http://php.net/manual/en/language.oop5.php
Read it for your own good.
Edit:
I know that following example can make you much lazy but I'll take a shoot and believe you will read more.
Example class for connections can look like:
class Mysql { protected $_host; protected $_dbname; protected $_username; protected $_password; protected $_db; public function __construct($host = null, $dbname = null, $username = null, $password = null) { $this->_host = $host; $this->_dbname = $dbname; $this->_username = $username; $this->_password = $password; } public function connect() { try { $this->_db = new PDO('mysql:host=' . $this->_host . ';dbname=' . $this->_dbname, $this->_username, $this->_password); } catch(PDOException $e){ echo $e->getMessage(); } } public function getDb() { return $this->db; } public function setHost($host) { $this->_host = $host; return $this; } public function getHost() { return $this->_host; } public function setDbname($dbname) { $this->_dbname = $dbname; return $this; } public function getDbname() { return $this->_dbname; } public function setUsername($username) { $this->_username = $username; return $this; } public function getUsername() { return $this->_username; } public function setPassword($password) { $this->_password = $password; return $this; } public function getPassword() { return $this->_password; } }
And example usage:
$mysql = new Mysql('mysql1.000webhost.com', 'a8130617_skola', 'something', 'something'); $mysql->connect();