Home > Backend Development > PHP Tutorial > 数据库连接有关问题

数据库连接有关问题

WBOY
Release: 2016-06-13 13:37:28
Original
754 people have browsed it

数据库连接问题

PHP code
<!--

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();// 关闭连接
     }
}


Copy after login


有 is not a valid PostgreSQL link resource 这个错误。

------解决方案--------------------
将connect()函数的内容检查下,看是否server、username、password、db都写对了。
------解决方案--------------------
有影响,除非重新连接数据库
------解决方案--------------------
没有影响!
在发起数据库连接时,php首先检查是否已经连接了,如果已经连接就不在做实际的连接了,直接返回已存在的连接
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template