// file CallCenter.php dbi = $db->connect(); } public function __construct() { $this->connectDB(); } public function main() { do{ $input_str = trim(fgets(STDIN)); $res = $this->getCountryInfo($input_str); if($res != false){ $flag = false; foreach ($res as $i=>$iv){ echo "Country: " . $iv['country_name'] . "\r\n"; echo "Capital: " . $iv['capital'] . "\r\n"; $flag = true; break; } if($flag == false){ echo "Country not found."; } }else{ echo "Could not read from DB."; } } while($input_str != 'Bye'); } private function getCountryInfo($str) { $result = $this->dbi->query(" SELECT `country_name`, `capital` FROM `countries` WHERE `country_name` = \"$str\" OR `country_code` = \"$str\" OR `iso_code` = \"$str\" LIMIT 0,1 "); if (is_object($result)){ return($result); } else{ return false; } } } // file Database.php db_name . ";host=" . $this->db_host, $this->db_user, $this->db_password); } public function setErrorExeption() { $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } public function connect() { $this->setErrorExeption(); return $this; } } // file callcenter_app.php main();