示例#1
0
 public function action_delete($id = null)
 {
     if ($database_server = Model_Database_Server::find($id)) {
         $database_server->delete();
         Session::set_flash('success', 'Deleted database_server #' . $id);
     } else {
         Session::set_flash('error', 'Could not delete database_server #' . $id);
     }
     Response::redirect('database/server');
 }
示例#2
0
 /**
  * Returns a database connection to the required database server from the database server Model.
  * 
  * @access public
  * @static
  * @param mixed $server_id
  * @return void
  */
 public static function connection($server_id)
 {
     if (!isset(static::$_database_connections[$server_id])) {
         $database_query = \Model_Database_Server::find($server_id);
         $config = array('type' => 'pdo', 'connection' => array('dsn' => ($database_query->type == 'mysql' ? 'mysql' : 'dblib') . ':host=' . $database_query->hostname . ($database_query->type == 'mysql' ? ';port=' : ':') . $database_query->port . ';dbname=asterisk', 'username' => $database_query->username == '' ? $database_query->username : $database_query->username, 'password' => $database_query->password == '' ? $database_query->password : $database_query->password, 'persistent' => false), 'Identifier' => '', 'Charset' => '');
         static::$_database_connections[$server_id] = \Database_Connection::instance('runQuery' . $database_query->hostname, $config);
     }
     return static::$_database_connections[$server_id];
 }
示例#3
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('Database_Query');
     $database_query = Model_Database_Query::find($id);
     $val = Model_Database_Query::validate('edit');
     if ($val->run()) {
         $database_query->title = Input::post('title');
         $database_query->description = Input::post('description');
         $database_query->query = Input::post('query');
         $database_query->cache_time = Input::post('cache_time');
         $database_query->database_server_id = Input::post('database_server_id');
         $database_query->database = Input::post('database');
         $database_query->username = Input::post('username');
         $database_query->password = Input::post('password');
         if ($database_query->save()) {
             Session::set_flash('success', 'Updated database_query #' . $id);
             Response::redirect('database/query');
         } else {
             Session::set_flash('error', 'Could not update database_query #' . $id);
         }
     } else {
         if (Input::method() == 'POST') {
             $database_query->title = $val->validated('title');
             $database_query->description = $val->validated('description');
             $database_query->query = $val->validated('query');
             $database_query->cache_time = $val->validated('cache_time');
             $database_query->database_server_id = $val->validated('database_server_id');
             $database_query->database = $val->validated('database');
             $database_query->username = $val->validated('username');
             $database_query->password = $val->validated('password');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('database_query', $database_query, false);
     }
     $this->template->set_global('server_id', null, false);
     $this->template->set_global('database_servers', Arr::assoc_to_keyval(Model_Database_Server::find('all'), 'id', 'title'), false);
     $this->template->title = "Database_queries";
     $this->template->content = View::forge('database/query/edit');
 }