设置额外的连接选项:
<?php
$mysqli = mysqli_init();
if (!$mysqli) {
die("mysqli_init failed");
}
// Specify connection timeout
$con -> options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
// Specify read options from named file instead of my.cnf
$con -> options(MYSQLI_READ_DEFAULT_FILE, "myfile.cnf");
$con -> real_connect("localhost","my_user","my_password","my_db");
?>
查看底部的程序样式示例。
options() / mysqli_options() 函数用于设置额外的连接选项并影响连接的行为。
$mysqli -> options(
option, value)
mysqli_options(
connection, option, value)
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
option | Required. Specifies the option to set. Can be one of the following values:
|
value | Required. Specifies the value for the option |
返回值: | 成功则为真。失败时为 FALSE |
---|---|
PHP 版本: | 5+ |
PHP 变更日志: | PHP 5.5:添加了 MYSQLI_SERVER_PUBLIC_KEY 选项 PHP 5.3:添加了 MYSQLI_OPT_INT_AND_FLOAT_NATIVE、MYSQLI_OPT_NET_CMD_BUFFER_SIZE、MYSQLI_OPT_NET_READ_BUFFER_SIZE 和 MYSQLI_OPT_SSL_VERIFY_SERVER_CERT 选项 |
设置额外的连接选项:
<?php
$con = mysqli_init();
if (!$con) {
die("mysqli_init failed");
}
// Specify connection timeout
mysqli_options($con, MYSQLI_OPT_CONNECT_TIMEOUT, 10);
// Specify read options from named file instead of my.cnf
mysqli_options($con, MYSQLI_READ_DEFAULT_FILE, "myfile.cnf");
mysqli_real_connect($con,"localhost","my_user","my_password","my_db");
?>
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!