현재 위치: > 함수 카테고리 모음> mysqli::query

mysqli::query

(mysqli_query) 데이터베이스에서 쿼리를 수행합니다
이름:mysqli::query
분류:mysqli
사용 언어:php
한 줄 설명:데이터베이스에서 쿼리를 수행하십시오.

정의 및 사용법

query() / mysqli_query() 함수는 데이터베이스에서 쿼리를 실행합니다.

예 1- 객체 지향 스타일

데이터베이스에서 쿼리를 수행하십시오.

 <? php
$ mysqli = new mysqli ( "localhost" , "my_user" , "my_password" , "my_db" ) ;

// 연결을 확인합니다
if ( $ mysqli- > connect_errno ) {
  Echo "MySQL에 연결하지 못했습니다 :" . $ mysqli- > connect_error ;
  출구 ( ) ;
}

// 쿼리를 실행합니다
if ( $ result = $ mysqli- > query ( "select * from persons" ) ) {
  Echo "반환 된 행은 다음과 같습니다." . $ result- > num_rows ;
  // 결과 세트를 릴리스합니다
  $ result- > free_result ( ) ;
}

$ mysqli- > close ( ) ;
?>

예 2- 절차 스타일

데이터베이스에서 쿼리를 수행하십시오.

 <? php
$ con = mysqli_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ;

if ( mysqli_connect_errno ( ) ) {
  Echo "MySQL에 연결하지 못했습니다 :" . mysqli_connect_error ( ) ;
  출구 ( ) ;
}

// 쿼리를 실행합니다
if ( $ result = mysqli_query ( $ con , "select * from persons" ) ) {
  Echo "반환 된 행은 다음과 같습니다." . mysqli_num_rows ( $ result ) ;
  // 결과 세트를 릴리스합니다
  mysqli_free_result ( $ result ) ;
}

mysqli_close ( $ con ) ;
?>
유사한 함수
인기 기사