Ejemplo n.º 1
0
 static function init($dbhost, $dbuser, $dbpass, $dbname)
 {
     self::$link = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
     self::$dbhost = $dbhost;
     self::$dbuser = $dbuser;
     self::$dbpass = $dbpass;
     self::$dbname = $dbname;
 }
Ejemplo n.º 2
0
Archivo: DB.php Proyecto: uhtoff/eCRF
 /**
  * Static method to set the current database
  * 
  * Can be sent with just the name of the database (excluding the server
  * prefix if applicable), will check to see if the user has already been
  * set, if it hasn't then will see if a username and password has been
  * sent and use those, if no user credentials available then returns
  * false.
  * 
  * @param string $db Name of the database (excluding prefix)
  * @param string $user Username of database user (optional - excl prefix)
  * @param string $pass Password for database user (optional)
  * @return boolean Success of setting DB
  */
 public static function setDB($db, $user = NULL, $pass = NULL, $host = 'localhost')
 {
     self::$dbhost = $host;
     $db = self::$dbprefix . $db;
     // Check to see if that DB already set
     if (self::getDB() === $db) {
         $setDB = self::getDBh();
         // Else see if username and password already set
     } elseif (array_key_exists($db, self::getUsers())) {
         self::$dbname = $db;
         $setDB = self::getDBh();
         // Else if new username and password sent, store them
     } elseif ($user && $pass) {
         self::addUser($db, $user, $pass);
         self::$dbname = $db;
         $setDB = self::getDBh();
         // Else set return to false as DB can't be set
     } else {
         $setDB = false;
     }
     return $setDB;
 }