tp5 연결 데이터베이스

2399 단어 tp5
1. 프로필 디렉터리 tp5\application\database.php
프로필을 통해 연결합니다.
메소드를 통해 링크할 수도 있습니다.
컨트롤러에서 데이터베이스를 연결하는 방법;조회 시 쓰기 방법과 시스템을 사용하는 DB 클래스 방법은 약간의 차이가 있다
   //            
 
    public function data1 ()
    {
    	$DB = Db::connect([
    		//      
		    'type'            => 'mysql',
		    //      
		    'hostname'        => '127.0.0.1',
		    //     
		    'database'        => 'user',
		    //    
		    'username'        => 'root',
		    //   
		    'password'        => 'root',
		    //   
		    'hostport'        => '3306',
    	]);

    	// dump($DB);
    	//     ,,,,      DB       
    	$data = $DB -> table("uu") -> select();
    	dump($data);
    }

 
2.기본사용,첨삭
컨트롤러가 구성 파일을 사용하여 데이터베이스 연결
디렉터 아래 파일(tp5\application\index\controller\Index.php) 쓰기
 fetch();
    }

    //            
    public function data()
    {
    	//          
    	$DB = new Db;
    	//     ,   uu     
    	$data = $DB::table("uu") -> select();
        //   sql  
    	//$data = $DB::query("select * from uu");

    	dump($data);
    }
  
}

http://www.tp.com/public/index.php/index/Index/data데이터 인쇄 테스트 가져오기
3. 템플릿 페이지 데이터 렌더링
 data();
        return $this -> fetch();
    }    
//              
    public function data()
    {
    	//          
    	$DB = new Db;
    	//     
    	$data = $DB::table("uu") -> select();

    	$this -> assign("user",$data);
    	// dump($data);
    }
}

4. 템플릿 페이지에서 렌더링 데이터를 참조할 수 있습니다.
tp5\application\index\view\index\index.html



	
	s


	
s
{volist name="user" id="vo"} {$vo.name} {/volist}

 
 
 

좋은 웹페이지 즐겨찾기