예제 #1
0
 public function testConnection()
 {
     $this->subject->disconnect();
     $result = $this->subject->connect();
     $this->assertTrue($result);
     // Try a reconnect
     $result = $this->subject->connect();
     $this->assertTrue($result);
     $result = $this->subject->isConnected();
     $this->assertTrue($result);
     $result = $this->subject->disconnect();
     $this->assertTrue($result);
     $result = $this->subject->isConnected();
     $this->assertFalse($result);
 }
예제 #2
0
 /**
  * @return null
  */
 public function testConnectClose()
 {
     $this->assertTrue($this->conn->connect());
     $this->assertEquals('connected', $this->conn->getStatus());
     $this->assertTrue($this->conn->isConnected());
     $this->assertFalse($this->conn->isError());
     $this->assertTrue($this->conn->close());
     $this->assertEquals('closed', $this->conn->getStatus());
     $this->assertFalse($this->conn->isDriver());
     $this->assertFalse($this->conn->isConnected());
     $this->assertFalse($this->conn->isError());
     /* lets see if we can connect again */
     $this->assertFalse($this->conn->connect());
     $this->assertEquals('closed', $this->conn->getStatus());
     $this->assertFalse($this->conn->isConnected());
     $this->assertTrue($this->conn->isError());
 }
예제 #3
0
 public function testIsConnected()
 {
     $adapterConnection = $this->prophesize(AbstractConnection::class);
     $adapterConnection->isConnected()->shouldBeCalled()->willReturn(true);
     $connection = new Connection($adapterConnection->reveal());
     $result = $connection->isConnected();
     static::assertTrue($result);
 }
예제 #4
0
 public static function setAktiv(Connection $conn, $BrancheID, ErrorQueue $err)
 {
     if (!$conn->isConnected()) {
         $err->addError("Keine Verbindung zur Datenbank.");
         return false;
     }
     $neuerStatus = Branche::STATUS_AKTIV;
     $q = new DBQuery("UPDATE branche SET Status='{$neuerStatus}' WHERE BrancheID='{$BrancheID}'");
     if (!$conn->executeQuery($q)) {
         $err->addError($conn->getLastError());
         return false;
     }
 }
예제 #5
0
 private function writepass(Connection $conn, $matrnr, $pass)
 {
     $pass = md5($pass);
     $matrnr = intval($matrnr);
     if ($conn->isConnected()) {
         // Email des Studenten auslesen
         $q = new DBQuery("SELECT Email FROM student WHERE MatrNr={$matrnr}");
         if ($res = $conn->executeQuery($q)) {
             if ($r = $res->getNextRow()) {
                 $email = $r[0];
             } else {
                 $this->last_error = "Die Matrikelnummer existiert nicht.";
                 return false;
             }
         } else {
             $this->last_error = "Die Matrikelnummer konnte nicht überprüft werden. " . $conn->getLastError();
             return false;
         }
         // Das neue Passwort wird geschrieben
         $q = new DBQuery("UPDATE student SET Pass='******' WHERE MatrNr={$matrnr}");
         if ($res = $conn->executeQuery($q)) {
             if ($res->affectedRows() > 0) {
                 return $email;
             } else {
                 $this->last_error = "Die Matrikelnummer existiert nicht.";
                 return false;
             }
         } else {
             $this->last_error = "Die Passwortänderung konnte nicht durchgeführt werden. " . $conn->getLastError();
             return false;
         }
     } else {
         $this->last_error = "Keine Verbindung zur Datenbank.";
         return false;
     }
 }
예제 #6
0
 public function testConnect()
 {
     $this->object->connect();
     $this->assertTrue($this->object->isConnected());
 }
 /**
  * @see Connection::isConnected()
  */
 public function isConnected()
 {
     return $this->childConnection->isConnected();
 }
예제 #8
0
 /**
  * Run a set of tasks
  *
  * @param Set $set A set of tasks to run
  * @param int $timeout Time in seconds for the socket timeout. Max is 10 seconds
  *
  * @return void
  * @see Net\Gearman\Set, Net\Gearman\Task
  */
 public function runSet(Set $set, $timeout = null)
 {
     foreach ($this->getServers() as $server) {
         $conn = Connection::connect($server, $timeout);
         if (!Connection::isConnected($conn)) {
             unset($this->servers[$server]);
             continue;
         }
         $this->conn[] = $conn;
     }
     $totalTasks = $set->tasksCount;
     $taskKeys = array_keys($set->tasks);
     $t = 0;
     if ($timeout !== null) {
         $socket_timeout = min(10, (int) $timeout);
     } else {
         $socket_timeout = 10;
     }
     while (!$set->finished()) {
         if ($timeout !== null) {
             if (empty($start)) {
                 $start = microtime(true);
             } else {
                 $now = microtime(true);
                 if ($now - $start >= $timeout) {
                     break;
                 }
             }
         }
         if ($t < $totalTasks) {
             $k = $taskKeys[$t];
             $this->submitTask($set->tasks[$k]);
             if ($set->tasks[$k]->type == Task::JOB_BACKGROUND || $set->tasks[$k]->type == Task::JOB_HIGH_BACKGROUND || $set->tasks[$k]->type == Task::JOB_LOW_BACKGROUND || $set->tasks[$k]->type == Task::JOB_EPOCH) {
                 $set->tasks[$k]->finished = true;
                 $set->tasksCount--;
             }
             $t++;
         }
         $write = null;
         $except = null;
         $read = $this->conn;
         socket_select($read, $write, $except, $socket_timeout);
         foreach ($read as $socket) {
             $resp = Connection::read($socket);
             if (count($resp)) {
                 $this->handleResponse($resp, $socket, $set);
             }
         }
     }
 }
예제 #9
0
 public static function setAktiv(Connection $conn, $studiengangID, $aktiv, ErrorQueue $err)
 {
     if (!$conn->isConnected()) {
         $err->addError("Keine Verbindung zur Datenbank.");
         return false;
     }
     $neuerStatus = Studiengang::STATUS_AKTIV;
     if ($aktiv == false) {
         $neuerStatus = Studiengang::STATUS_INAKTIV;
     }
     $q = new DBQuery("UPDATE studiengang SET status='{$neuerStatus}' WHERE studiengangID='{$studiengangID}'");
     if (!$conn->executeQuery($q)) {
         $err->addError($conn->getLastError());
         return false;
     }
 }
예제 #10
0
 public static function enumDozenten(Connection $conn)
 {
     $q = new DBQuery("SELECT d.PDozentID, d.Name, d.EMail, d.Telefon, log.Username FROM dozent d LEFT JOIN dozentlogin log ON (log.PDozentID=d.PDozentID) ORDER BY d.Name");
     if ($conn->isConnected()) {
         return $conn->executeQuery($q);
     } else {
         return false;
     }
 }
예제 #11
0
 public static function enumFreigaben(Connection $conn, ErrorQueue $err)
 {
     $q = new DBQuery("SELECT FreigabeID, FreigabeBereich FROM freigabe ORDER BY FreigabeID");
     if ($conn->isConnected()) {
         if ($result = $conn->executeQuery($q)) {
             return $result;
         } else {
             $err->addError("Datenbankfehler: " . $conn->getLastError());
         }
     } else {
         return false;
     }
 }
예제 #12
0
 /**
  * @see Connection::isConnected()
  */
 public function isConnected()
 {
     return true;
     krumo('DBArrayConnection isConnected ');
     die;
     return $this->childConnection->isConnected();
 }
예제 #13
0
 public static function neuerStudentAnmelden($matrnr, $name, $vorname, $email, $fhemail, ErrorQueue $err, Connection $conn)
 {
     $gen = new PassGenerator();
     $pass = $gen->createNewPass(0);
     $mdpass = md5($pass);
     // Matrikelnummer überprüfen
     $matrnr1 = $matrnr;
     $matrnrlen = strlen($matrnr1);
     $matrnr = intval($matrnr);
     if ($matrnrlen != strlen($matrnr) || $matrnr <= 0) {
         $err->addError("Die Matrikelnummer ist ungültig.");
         return false;
     }
     $name = addslashes($name);
     $email = addslashes($email);
     $vorname = addslashes($vorname);
     $fhemail .= "@stud.fh-luebeck.de";
     $fhemail = addslashes($fhemail);
     if (strcmp($name, "") == 0 || strcmp($vorname, "") == 0 || strcmp($email, "") == 0 || strcmp($fhemail, "") == 0) {
         $err->addError("Bitte f&uuml;ll alle Felder aus.");
         return false;
     }
     if (!Mailer::checkMail($email)) {
         $err->addError("Die E-Mail-Adresse hat das falsche Format.");
         return false;
     }
     if (!Mailer::checkMail($fhemail)) {
         $err->addError("Die FHL-E-Mail-Adresse hat das falsche Format.");
         return false;
     }
     if ($conn->isConnected()) {
         $q = new DBQuery("INSERT INTO student(MatrNr, Name, EMail, Pass, Vorname) VALUES({$matrnr}, '{$name}', '{$email}', '{$mdpass}', '{$vorname}')");
         if ($conn->executeQuery($q)) {
             Mailer::mailit($fhemail, "Deine Anmeldung", "Hallo {$name},\n danke für Deine Anmeldung. Deine Login-Daten lauten:\n Passwort: \"{$pass}\"\nMatrikelnummer: {$matrnr}\n\n" . Studiengang::getSemsysInfo($conn, $err));
             return true;
         } else {
             $err->addError("Die Anmeldung konnte nicht durchgef&uuml;hrt werden. Diese Matrikelnummer ist schon registriert.");
             return false;
         }
         // Query executed
     } else {
         $err->addError("Keine Verbindung zur Datenbank.");
         return false;
     }
     // Connected
 }
예제 #14
0
 public static function enumGroessen(Connection $conn, ErrorQueue $err)
 {
     $q = new DBQuery("SELECT UnternehmensgroesseID, Mitarbeiterzahl, MindestName FROM unternehmensgroesse");
     if ($conn->isConnected()) {
         if ($result = $conn->executeQuery($q)) {
             return $result;
         } else {
             $err->addError("Datenbankfehler: " . $conn->getLastError());
         }
     } else {
         return false;
     }
 }