Php mysql_close()的具体功能是什么?
说明: 假设我正在从php页面获取一些数据,如下所示Php mysql_close()的具体功能是什么?,php,Php,说明: 假设我正在从php页面获取一些数据,如下所示 <?php include 'connect_to_database.php'; while ($data = mysqli_fetch_array(mysqli_query($con,"select * from myTable"),MYSQLI_BOTH)) { echo $data['product']; } mysqli_close($con); ?> 现在什么是mysql_close$con;这样做的确
<?php
include 'connect_to_database.php';
while ($data = mysqli_fetch_array(mysqli_query($con,"select * from myTable"),MYSQLI_BOTH))
{
echo $data['product'];
}
mysqli_close($con);
?>
现在什么是mysql_close$con;这样做的确切方式是仅关闭此页面的连接,或作为一个整体断开网站与数据库的连接,而数据库必须重新连接才能正常工作。。此外,我还了解到,在php末尾写exit是一个非常好的做法,因为如果我们不这样做,那么页面将继续在服务器中执行,从而占用空间
有人能解释一下吗 它关闭变量$con引用的连接。可能有多个连接,然后它只关闭您在mysqli_close的第一个参数中指定的连接。mysqli_close仅关闭该特定页面与数据库的连接,没有什么比断开网站与数据库的连接更重要的了,数据库必须再次连接才能工作,每个页面上都会启动一个新连接,一旦执行结束,该连接将自动关闭。mysqli_close将在执行结束之前将其关闭,为了演示这一点
<?php
// connection starts here
mysqli_query($link, "whatever stuff you need to do");
?>
// The connection is closed here
在如何使用mysqli_close的另一个示例中
<?php
// connection starts here
mysqli_query($link, "whatever stuff you need to do");
mysqli_close($link); // the connection is closed here
// do whatever more stuff you have to do that are unrelated to the database
?>
至于退出,它的唯一用途是跳出代码,把它放在代码末尾是没有用的
在下面这样使用它是没有用的:
<?php
echo 'Hi';
echo 'Bye';
exit(); // this is useless because all code has been executed already
?>
下面的示例非常有用:
<?php
echo 'Hi';
exit(); // this is useful as it stops the execution of whatever code is below it.
echo 'Bye';
?>
由于可以向服务器发送许多请求,因此当连接未关闭并保持打开状态时,服务器可能会耗尽可用连接。当页面执行完成时,数据库连接将自动终止。不过,当你用完资源后,释放资源是一个好习惯。好吧!那么在页面的末尾写下exit呢???@RksRock这绝对没用。好吧。。thanx先生: