# close

mysqli::close

mysqli_close

Closes a previously opened database connection

# 

ENTITY

ENTITY

<div data-wrapper="1" role="mysqli">

public

</div>

<div data-wrapper="1" role="mysqli">

true

</div>

<div data-wrapper="1" role="mysqli">

mysqli::close

</div>

ENTITY

true

mysqli_close

mysqli

mysql

Closes a previously opened database connection.

Open non-persistent MySQL connections and result sets are automatically closed when their objects are destroyed. Explicitly closing open connections and freeing result sets is optional. However, it's a good idea to close the connection as soon as the script finishes performing all of its database operations, if it still has a lot of processing to do after getting the results.

# 

ENTITY

# 

ENTITY

ENTITY

# 

ENTITY

| ENTITY | ENTITY |
|----|----|
| 8.0.0 | This function now always returns ENTITY. Previously it returned ENTITY on failure. |

# 

ENTITY

<div class="example">

<div class="title">

mysqli::close example

</div>

ENTITY

```
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

$result = $mysqli->query("SELECT Name, CountryCode FROM City ORDER BY ID LIMIT 3");

/* Close the connection as soon as it's no longer needed */
$mysqli->close();

foreach ($result as $row) {
    /* Processing of the data retrieved from the database */
}

   
```

ENTITY

```
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_connect("localhost", "my_user", "my_password", "world");

$result = mysqli_query($mysqli, "SELECT Name, CountryCode FROM City ORDER BY ID LIMIT 3");

/* Close the connection as soon as it's no longer needed */
mysqli_close($mysqli);

foreach ($result as $row) {
    /* Processing of the data retrieved from the database */
}

   
```

</div>

# 

ENTITY

> [!NOTE]
> `mysqli_close` will not close persistent connections. For additional details, see the manual page on [persistent connections](#features.persistent-connections).

# 

ENTITY

mysqli::\_\_construct, `mysqli_init`, `mysqli_real_connect`, `mysqli_free_result`