Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- php pdo mysql connect - confusing syntax problem
- <?php
- $mysql_host='mysql1.000webhost.com';
- $mysql_dbname='a8130617_skola';
- $mysql_username='something';
- $mysql_password='something';
- class mysql {
- try{
- public $db = new PDO("mysql:host=$mysql_host;dbname=$mysql_dbname",
- $mysql_username, $mysql_password);
- }
- catch(PDOException $e){
- echo $e->getMessage();
- }
- } //ERROR EXCLAMATION MARK HERE???
- ?>
- try{
- public $db = new PDO("mysql:host=$mysql_host;dbname=$mysql_dbname",
- $mysql_username, $mysql_password);
- }
- catch(PDOException $e){
- echo $e->getMessage();
- }
- 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;
- }
- }
- $mysql = new Mysql('mysql1.000webhost.com', 'a8130617_skola', 'something', 'something');
- $mysql->connect();
Add Comment
Please, Sign In to add comment