如何关闭prepare语句连接? 这是对的? - PDO

i use this code, for example:

$result = $link->prepare("SELECT * FROM animals WHERE id = '$id'");
$result->execute();
$row = $result->fetch(PDO::FETCH_ASSOC);
$result = null;
$link = null;

It's ok use "$result = null;" to close this connection?

It's ok use "$result = null;" to close this connection?

It would not close the database connection. However it closes the PDOStatement $result , which is probably what you were concerned about.

If you want to close the connection with all it's associated resources, you do fine with

$link = null;

Which you have, too. So I don't see any problems at all here. I must even admit, I wonder a bit what made you asking.