I am designing a site and I was just wondering if the folowing class I
designed, which is fairly simple, should be used.
<?php
class DB {
private $username;
private $password;
private $db;
private $server;
//contruct
function __contruct(string $username,$password,$server,string $db){
$this->username = $username;
$this->password = $password;
$this->db = $db;
$this->server = $server;
}
//connect
static connect () {
@mysql_connect($this->server,$this->username,$this->password) or
die ("Could not establish a connection with the MySQL
database.\n");
@mysql_select_db($this->db) or
die ("Could not select the database" . $this->db . "\n");
}
//getter methods
function get_username(){
return $this->username;
}
function get_password (){
return $this->password;
}
function get_db(){
return $this->db;
}
function get_server (){
return $this->server;
}
//setter methods
function set_username ($username){
$this->username = $username;
}
function set_password ($password){
$this->password = $password;
}
function set_db ($db){
$this->db = $db;
}
function set_server ($server){
$this->server = $server;
}
}
?>
I figured if I wanted to change which database to use I could do it
quickly with a setter method, check it with a getter method. Also,
apply this to usernames and passwords and servers.
Is this too much code for a simple task?