PHP mysqli stmt_init() 함수
예 - 객체 지향 스타일
명령문을 초기화하고 stmt_prepare()와 함께 사용할 객체를 반환합니다.
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
$city="Sandnes";
// Create a prepared statement
$stmt = $mysqli -> stmt_init();
if ($stmt
-> prepare("SELECT District FROM City WHERE Name=?")) {
// Bind parameters
$stmt -> bind_param("s", $city);
// Execute query
$stmt -> execute();
// Bind result variables
$stmt -> bind_result($district);
// Fetch value
$stmt -> fetch();
printf("%s is in district %s", $city, $district);
// Close statement
$stmt -> close();
}
$mysqli -> close();
?>
하단의 절차적 스타일의 예를 보십시오.
정의 및 사용
stmt_init() / mysqli_stmt_init() 함수는 명령문을 초기화하고 mysqli_stmt_prepare()에 적합한 객체를 반환합니다.
통사론
객체 지향 스타일:
$mysqli -> stmt_init()
절차 스타일:
mysqli_stmt_init(connection)
매개변수 값
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
기술적 세부 사항
반환 값: | 객체를 반환 |
---|---|
PHP 버전: | 5+ |
예 - 절차 스타일
명령문을 초기화하고 mysqli_stmt_prepare()와 함께 사용할 객체를 반환합니다.
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit;
}
$city="Sandnes";
// Create a prepared statement
$stmt = mysqli_stmt_init($con);
if (mysqli_stmt_prepare($stmt, "SELECT District FROM City WHERE Name=?")) {
// Bind parameters
mysqli_stmt_bind_param($stmt, "s", $city);
// Execute query
mysqli_stmt_execute($stmt);
// Bind result variables
mysqli_stmt_bind_result($stmt, $district);
// Fetch value
mysqli_stmt_fetch($stmt);
printf("%s is in district %s", $city, $district);
// Close statement
mysqli_stmt_close($stmt);
}
mysqli_close($con);
?>
❮ PHP MySQLi 참조