Let say you have this code:
<?php
class Db
{
private $database_server;
private $username;
private $password;
private $database_name;
public $connection;
__construct($db_server, $db_name)
{
$database_server = $db_server;
$database_name = $db_name;
}
function dbconnect()
{
if ($database_server == 'postgresql')
{
$connection = pg_connect("dbname=$database_name");
} elseif ($database_server == '') {
die('No database server specified');
}
}
}
?>
Now let's say that I have another class, class XYZ, that have code to run different queries based on what $database_server is. So if I type $db = new Db('postgresql', 'monkeys'), then I'd like class XYZ to run a query using postgresql functions rather than mysql functions. How would I make class XYZ aware of the value of $database_name? Would making it a public variable be safe?