コード例 #1
0
 /**
  * @param Host $_host
  * @param string $_database
  * @param Credential $_credential
  * @param Logger $_logger
  */
 function __construct(Host $_host, $_database, Credential $_credential, Logger $_logger = null)
 {
     $this->logger = $_logger;
     $this->connection = mysql_connect($_host->getHost(), $_credential->getUsername(), $_credential->getPassword(), true);
     if (!$this->connection) {
         throw new DatabaseException(mysql_error($this->connection));
     }
     /* ## LOGGER ## */
     if (isset($this->logger)) {
         $this->logger->DEBUG('mysql_connect: ' . $_host->getHost());
     }
     $selected = mysql_select_db($_database, $this->connection);
     if (!$selected) {
         throw new DatabaseException(mysql_error($this->connection));
     }
     /* ## LOGGER ## */
     if (isset($this->logger)) {
         $this->logger->DEBUG('mysql_select_db: ' . $_database);
     }
 }
コード例 #2
0
ファイル: HostTest.php プロジェクト: sugiphp/routing
 public function testHost()
 {
     $route = new Host("/");
     $this->assertEquals("", $route->getHost());
     // returns "" ? or it should be NULL / FALSE ?
     $this->assertSame(null, $route->getHost());
     $route->setHost("example.com");
     $this->assertEquals("example.com", $route->getHost());
     $route->setHost(null);
     $this->assertEquals("", $route->getHost());
     $this->assertSame(null, $route->getHost());
     // wrong but will be fixed
     // EDIT: this will not be fixed!
     // $route->setHost("http://example.com/users/list?page=1");
     // $this->assertEquals("example.com", $route->getHost());
     // sub domain
     $route->setHost("sub.example.com");
     $this->assertEquals("sub.example.com", $route->getHost());
     // check parameterized hosts
     $route->setHost("{subdomain}.example.com");
     $this->assertEquals("{subdomain}.example.com", $route->getHost());
 }