Working with DB

Go to your tft database (introduced in Chapter 3, Creating and installing new application / site) and create a table using following SQL statement:


CREATE TABLE `test` (
  `id` int(10) unsigned NOT NULL,
  `world_type` varchar(45) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
				
			

Above will create DB table called test. Enter few values in it, for example:

Replace the run() method with: public function run() {
    
$dbc $this->get_dbc(); // $dbc now holds DB_Connection object that is connected to our tft database

    
$sql "select world_type from test where id = 3"// SQL that will load row with id = 3
    
$rez $dbc->execute($sql); // executing the SQL statement against the DB
    
if (!$rez->is_eod()) { // checking if there is a result set (eod means End Of Data)
        
$rez_obj $rez->fetch_object(); // getting the result
        
$this->export('world_type'$rez_obj->WORLD_TYPE); // exporting to tple
    
}

    return 
$this->get_view('default');
}

Hit refresh. You should see Hello wonderful world!