我读了doumentation但我不完全理解差异.
连接对象在这有什么区别?我没有发现任何帖子.
我误解了它.两者都没有标志.为什么他们不添加旗帜作为一部分mysqli_connect?任何具体原因?我应该使用哪一个?
小智 5
mysqli_real_connect()并且mysqli_connect在方式上不同
mysqli_real_connect() 接受的选择比 mysqli_connect
例如,我正在为我的负载均衡器构建运行状况检查脚本,并且我想设置非常低的连接超时。
现在必须使用以下命令设置连接超时:
mysqli_options() 带有选项名称 MYSQLI_OPT_CONNECT_TIMEOUT
现在,问题mysqli_options()是应该在mysqli_init()之后和mysqli_real_connect()之前调用它。
mysqli_connect 不能用于此目的。
希望这种解释有所帮助。
<?php
//create the object
$connection = mysqli_init();
//specify the connection timeout
$connection->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3);
//specify the read timeout
$connection->options(MYSQLI_OPT_READ_TIMEOUT, 3);
//initiate the connection to the server, using both previously specified timeouts
$connection->real_connect('server', 'user', 'pass', 'database');
?>
Run Code Online (Sandbox Code Playgroud)