mysqli::select_db

(PHP 5, PHP 7, PHP 8)

mysqli::select_db -- mysqli_select_db — 데이터베이스 쿼리를 위한 기본 데이터베이스 선택


설명

객체 지향 스타일

public mysqli::select_db(string $database): bool

절차적 스타일

mysqli_select_db(mysqli $mysql, string $database): bool

데이터베이스 연결에 대해 쿼리를 수행할 때 사용할 기본 데이터베이스를 선택합니다.

메모: 이 함수는 연결에 대한 기본 데이터베이스를 변경하는 데만 사용해야 합니다. mysqli_connect()에서 4번째 매개변수로 기본 데이터베이스를 선택할 수 있습니다.


매개변수

mysql
절차적 스타일 전용: mysqli_connect() 또는 mysqli_init()에 의해 반환된 mysqli 객체
database
데이터베이스 이름입니다.

반환 값

성공하면 true를, 실패하면 false를 반환합니다.


Examples

예제 #1 mysqli::select_db() 예제

객체 지향 스타일

                  
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");

/* get the name of the current default database */
$result = $mysqli->query("SELECT DATABASE()");
$row = $result->fetch_row();
printf("Default database is %s.\n", $row[0]);

/* change default database to "world" */
$mysqli->select_db("world");

/* get the name of the current default database */
$result = $mysqli->query("SELECT DATABASE()");
$row = $result->fetch_row();
printf("Default database is %s.\n", $row[0]);
                  
                

절차적 스타일

                  
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "test");

/* get the name of the current default database */
$result = mysqli_query($link, "SELECT DATABASE()");
$row = mysqli_fetch_row($result);
printf("Default database is %s.\n", $row[0]);

/* change default database to "world" */
mysqli_select_db($link, "world");

/* get the name of the current default database */
$result = mysqli_query($link, "SELECT DATABASE()");
$row = mysqli_fetch_row($result);
printf("Default database is %s.\n", $row[0]);
                  
                

위의 예는 다음을 출력합니다.

Default database is test.
Default database is world.
                

기타