I am learning MySQL and PHP and I want to dispel this doubt. Maybe is stupid, but I want to learn in the good way and I didn´t find the answer.
So, I have several QUERIES and my doubt is: Do I have to close with $result->close(); EACH ONE or JUST ONE at the final with $conn->close();
Example 1: Closing EACH ONE
$sql = "CREATE TABLE atable (
idatable INT(5) NOT NULL AUTO_INCREMENT,
name VARCHAR(10) NOT NULL,
lastname VARCHAR(10) NOT NULL,
PRIMARY KEY(idatable))";
$result = $conn->query($sql);
if(!$result) {
die($conn->error);
}
$result->close();
$sql = "DESCRIBE atable";
$result = $conn->query($sql);
if(!$result) {
die($conn->error);
}
// Here more code...
$result->close();
$sql = "SELECT * FROM atable";
$result = $conn->query($sql);
if(!$result) {
die($conn->error);
}
// Here more code...
$result->close();
$conn->close();
Example 2: closing ONE time at the END
$sql = "CREATE TABLE atable (
idatable INT(5) NOT NULL AUTO_INCREMENT,
name VARCHAR(10) NOT NULL,
lastname VARCHAR(10) NOT NULL,
PRIMARY KEY(idatable))";
$result = $conn->query($sql);
if(!$result) {
die($conn->error);
}
$sql = "DESCRIBE atable";
$result = $conn->query($sql);
if(!$result) {
die($conn->error);
}
// Here more code...
$sql = "SELECT * FROM atable";
$result = $conn->query($sql);
if(!$result) {
die($conn->error);
}
// Here more code...
$result->close();
$conn->close();
Remember that I am learning! Thanks!