SHARE
TWEET

var for a class in PHP

a guest Feb 26th, 2012 27 Never
  1. class flexibleAccess{
  2.  
  3.   var $dbName = 'mydatabase';
  4.        
  5. class flexibleAccess{
  6.  
  7.       var $dbName = $_SESSION['mydatabase'];
  8.        
  9. class flexibleAccess{
  10.  
  11.    private $dbName;
  12.  
  13.    function __construct() {
  14.          $this->dbName = $_SESSION['mydatabase'];
  15.    }
  16. }
  17.        
  18. constant("DBNAME", 'mydatabase');
  19.        
  20. require_once 'dbconfig.php';
  21.  
  22. class flexibleAccess {
  23.   private $dbname;
  24.  
  25.   // set the default database name to the constant DBNAME
  26.   // but allow override
  27.   public function __construct ( $dbname = DBNAME )
  28.   {
  29.     $this->dbname = $dbname;
  30.   }
  31. }
  32.        
  33. require_once 'flexibleaccess.php';
  34.  
  35. $db = new flexibleaccess();
  36.        
  37. <?php
  38. $login = new flexibleAccess();
  39. $login->dbName = $_SESSION['mydatabase'];
  40. ?>
RAW Paste Data
Top