Heim >Backend-Entwicklung >PHP-Tutorial > 数据库连接有关问题
数据库连接问题
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> 文件1 $search_db = new SearchDo(); if ($search_db->connect() === false) { //数据库连接 exit; } if( $area_kubun_id == '') { //地域 $list_area = new AreaList(); $area_list = $list_area->createList(); $smarty->assign('area_list', $area_list); }else { $area_list =$search_db->getAreaById($area_kubun_id); $smarty->assign('area_list', $area_list); } 文件2 class AreaList extends SelectList { function AreaList(){ $sql = SQL_AREA_LIST_SELECT; $this->sql = $sql; $this->SelectList(); } } 文件3 class SelectList extends BoatDb { function SelectList() { $this->BoatDb(); $this->connect(); // 数据库连接 } function createList() { --数据库操作-- $this->close();// 关闭连接 } }