Jump to content

DB Security with OOP (accidental prevention)


Mudsaf

Recommended Posts

Yo, back with OOP related question. So if i have database connection with OOP style (example below)

class MyDB {
	protected $con;
	private $db_host = "x"; //Database host
	private $db_user = "x"; //Database username
	private $db_pass = "x"; //Database user password
	private $db_name = "x"; //Database name
	
	public function connect() {
	$this->con = new mysqli($this->db_host, $this->db_user, $this->db_pass, $this->db_name);
		if ($this->con->connect_error) {
		die("Connection error, please try again later.");
		} else {
		return $this->con;
		}
	}
}

Is there way to prevent var_dump showing the database connection information if linked. (example below)

$mydb = new MyDB;
$con = $mydb->connect();

var_dump($con);

^Example like this, ofc I wouldn't dump the connection info itself, but if its linked in other class i think it shows it anyways when doing the var_dump.

Link to comment
Share on other sites

  • Mudsaf changed the title to DB Security with OOP (accidental prevention)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...