Database::open PHP Method

open() public method

public open ( )
    public function open()
    {
        $this->close();
        $this->conn = mysqli_connect($this->host, $this->username, $this->password, $this->dbname);
        if (!$this->conn) {
            throw new SwarmException("Connection to {$this->host} failed.\nMySQL Error " . $this->lastErrNo() . ': ' . $this->lastErrMsg());
        }
        if (method_exists($this->conn, 'set_charset')) {
            if (!$this->conn->set_charset('binary')) {
                throw new SwarmException('Error setting character set on MySQL connection');
            }
        }
        $this->isOpen = true;
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 public function getMainNavigation()
 {
     $d = new Database();
     $d->open('hacker_blog');
     $sql = "SELECT * FROM navigation ";
     if ($this->type == 'private') {
         $sql .= " WHERE public = 0 ";
     } else {
         $sql .= " WHERE private = 1 ";
     }
     $s = $d->q($sql);
     if ($s && $d->numrows() >= 1) {
         $arr = array();
         while ($r = $d->mfa()) {
             //print_r($r);
             array_push($arr, $r);
         }
         $this->messages = array("success" => "Found Navigation");
         $this->current = $arr;
         return $arr;
         $d->close();
     } else {
         $this->messages = array("error" => "Could not Find Navigation");
         $d->close();
         return false;
     }
 }
All Usage Examples Of Database::open