课程: PHP with MySQL Essential Training: 1 The Basics

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Error handling

Error handling

- [Instructor] Over the last several movies, we've learned how to connect to a database, how to make a query for data, and then how to use that data in our website. Now, I want to talk about what to do when something goes wrong in that process and how can we handle it when it does. There are two more functions that we're going to use from the mysqli API for this. The first is mysqli_connect_errno that's short for error number, E-R-R-N-O short for error number. And then mysqli_connect_error. Errno is going to return the error code from the last call that we made to connect to the database. So whatever that was, whatever the last call to connect the database was, we're going to be able to retrieve the error code that was there. If there is no error code, then it'll come back and turn nothing. There's nothing there. The mysqli_connect_error function is going to return a string description of that last connect error. So it does the exact same thing it looks to see what the error was, but…

内容