Php 多个mysql\U连接关闭在一起
如果我对同一台mysql服务器使用多个Php 多个mysql\U连接关闭在一起,php,mysql,Php,Mysql,如果我对同一台mysql服务器使用多个mysql\u connect(),会发生什么?我在一些函数中使用此函数,并在其中一个函数中调用mysql\u close(),这会导致其他连接也关闭 我如何解决它 声明一个变量,其中将存储NewLink <?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connec
mysql\u connect()
,会发生什么?我在一些函数中使用此函数,并在其中一个函数中调用mysql\u close()
,这会导致其他连接也关闭
我如何解决它 声明一个变量,其中将存储
NewLink
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
如果使用相同的参数对mysql\u connect()
进行第二次调用,
不会建立新的链接,而是
将返回已打开的链接。新的链接参数
修改此行为并使mysql_connect()始终打开新的
链接,即使之前使用相同的
参数。在SQL安全模式下,忽略此参数
使用标识符打开mysql连接,例如:
$connection1 = mysql_connect('server','user','password');
$connection2 = mysql_connect('server','user','password');
mysql_close($connection1);
这将只关闭$connection1
bool mysql_close ([ resource $link_identifier ] )
mysql_close() closes the non-persistent connection to the MySQL server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is used.
Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.
检查此参考:http://in2.php.net/manual/en/function.mysql-close.php只是不要使用多个连接。
连接一次,然后运行函数,然后调用mysql\u close一次(不需要)hello这是这个问题的有用内容!为什么你点击没有用!它实际上帮助了别人,而不是你的。老兄,你接受了错误的答案。@Schraspel上校:正因为这个用法,给我-1分?我们有时需要进行多重连接。我的问题是关于连接概念的问题。这不是真的。您的问题不是关于“概念”,而是关于代码中错误的连接用法。对于问题中的代码,根本不需要多个连接。一旦你需要它-欢迎你问它。