From the course: PHP: Object-Oriented Programming with Databases

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Disconnect from the database

Disconnect from the database

- [Instructor] We've seen how we can connect to the database, and we've seen how we can use that database connection. Now let's complete the cycle by talking about how we can disconnect from the database. So the way that we create a new database connection is with that new mysqli object command and then we can work with it, when we're finally done we want to close it. In the past you would do that with mysqli_close and pass it in the database connection. But as we've seen so often before, there's a close method that is on that database object that we can simply call and it will close the connection. Now this is completely optional. It's not something that you have to do. If you forget to do it, then once your PHP script exits, PHP will close the connection. When that object goes away, it knows that it's time to close the connection. But it is a good practice to go ahead and do it anyway. So we want to be good programmers…

Contents