From the course: PHP: Object-Oriented Programming with Databases
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Disconnect from the database - PHP Tutorial
From the course: PHP: Object-Oriented Programming with Databases
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 and follow the best practices. In order to close the connection,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.