定義和用法
這個mysqli_options()函數用於設置額外的連接選項。如果要設置多個選項,則需要多次調用此函數。
用法
mysqli_options($con, $option, $value)
參數
Sr.No | 參數及說明 |
---|---|
1 |
con(Mandatory) 這是一個表示與 MySQL 服務器的連接的對象。 |
2 |
option(Mandatory) 這是一個整數值,表示您要設置的連接選項。它可以是以下之一 -
|
3 |
value(Mandatory) 這是一個整數值,表示所選選項的值。 |
返回值
此函數返回布爾值,如果成功則返回 true,如果失敗則返回 false。
PHP版本
這個函數最初是在 PHP 版本 5 中引入的,適用於所有後續版本。
示例
以下示例演示了 mysqli_options() 函數的用法(程序風格) -
<?php
//Creating the connection
$con = mysqli_connect("localhost","root","password","test");
mysqli_options($con, MYSQLI_OPT_NET_CMD_BUFFER_SIZE, 15);
if($con){
print("Connection Established Successfully");
}else{
print("Connection Failed ");
}
?>
這將產生以下結果 -
Connection Established Successfully
示例
在麵向對象風格中,這個函數的語法是 $con-> options();以下是麵向對象樣式 $minus 中此函數的示例;
<?php
//Creating the connection
$con = new mysqli("localhost","root","password","test");
$con->options(MYSQLI_OPT_NET_CMD_BUFFER_SIZE, 15);
if($con){
print("Connection Established Successfully");
}else{
print("Connection Failed ");
}
?>
這將產生以下結果 -
Connection Established Successfully
示例
在麵向對象風格中,這個函數的語法是 $con-> options();以下是麵向對象樣式 $minus 中此函數的示例;
<?php
$connection_mysql = mysqli_init();
if (!$connection_mysql){
die("mysqli_init failed");
}
mysqli_options($connection_mysql, MYSQLI_OPT_CONNECT_TIMEOUT, 10);
mysqli_options($connection_mysql,MYSQLI_READ_DEFAULT_FILE,"configure.cnf");
$connection_mysql = mysqli_real_connect($connection_mysql, "localhost","root","password","mydb");
if (!$connection_mysql){
print("Connect Error:" . mysqli_connect_error());
}else{
print("Connection was successful");
}
?>
這將產生以下結果 -
Connection was successful
相關用法
- PHP mysqli_get_server_info()用法及代碼示例
- PHP mysqli_data_seek()用法及代碼示例
- PHP mysqli_insert_id()用法及代碼示例
- PHP mysqli_fetch_assoc()用法及代碼示例
- PHP mysqli_connect_error()用法及代碼示例
- PHP mysqli_fetch_all()用法及代碼示例
- PHP mysqli_next_result()用法及代碼示例
- PHP mysqli_stmt_affected_rows()用法及代碼示例
- PHP mysqli_begin_transaction()用法及代碼示例
- PHP mysqli_real_escape_string()用法及代碼示例
- PHP mysqli_fetch_lengths()用法及代碼示例
- PHP mysqli_character_set_name()用法及代碼示例
- PHP mysqli_free_result()用法及代碼示例
- PHP mysqli_fetch_row()用法及代碼示例
- PHP mysqli_debug()用法及代碼示例
- PHP mysqli_commit()用法及代碼示例
- PHP mysqli_fetch_field()用法及代碼示例
- PHP mysqli_kill()用法及代碼示例
- PHP mysqli_thread_safe()用法及代碼示例
- PHP mysqli_get_connection_stats()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP mysqli_options() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。