 So in this module, we will be discussing about connecting my SQL from PHP. Okay. So how are you going to do this? There are two fundamental main methods, main techniques on which there's a lot of difference among the programmers. And they are very emotional about it. We don't go into the emotions. We will only present the facts before you and it is up to you to decide. Then I'll also give you a sample of how the connection is made, how the connection is made, and then how the error messages are handled. And they should be handled in an intelligent way. The system should never be allowed to crash. And finally, how the data is going to be read. So this is the outline of the module so that this outline I have already mentioned. Now let us go and look at these two main ways of connecting two main ways. Let's let's look at them. So I have this my SQLI method and the PDO method. Now the my SQLI method is the most complete method. It has a very comprehensive access and it has procedural as well as object oriented interfaces. Now the downside is that there is so much functionality. There are so much features that it can be or it is overwhelming for somebody who is new in this domain, right? However, if you think that PHP is going to be your future, then this is the approach you should be adopting. Understood? The other approach is the PDO PHP data objects which sits between my SQL server and the PHP engine. That's where it is, right? And nice and simple clean classes. Nice and simple clean classes. And whatever you are doing, you can do it with less learning. You can do a lot with less learning and it talks to different databases, the big three databases, so to say. So these are the differences between these two approaches. I believe you understand this. Now how do we make a connection? Okay, we make the connection which consists of three parts. Okay, which consists of three parts, which is the DSN, which is the user name and which is the password. What is DSN? DSN is the database source name. It is simply a string that describes attributes of the connection, such as the type of database system, the location of the database and the database name. Okay, for example, the following DSN can be used to connect to my SQL database called my database running on the same machine as the PHP engine. Okay, over here. If the host isn't specified, it is the local host. So putting everything together, this is what we have, right? So when you are finished with the connection, you should close it so that is freed up for other scripts to use. Although the PHP engine usually closes connection. So how do you close it? You just assign null value and it closes the connection. I believe this thing is clear to you. Handling the errors. Okay. And to set the PDO to raise exceptions, whenever database error occurs, you use the PDO set attribute method to see and set your PDO objects error mode as follows. Okay, this is what you do over here. And now you can capture any error that might occur when connecting to the database by using a try catch. Okay, try and catch over here. Code block, if you are writing a sophisticated application, you probably log the error messages to a file and possibly send an email to the webmaster. Now PHP runs the code within the try block. If an exception is raised by the PDO, the catch block stores the PDF exception in the over here. Okay, then displays the error message with this over here. So things are very clear, I believe. Okay, and for example, if the dollar password variable in the script contained an incorrect password, you would see a message like this appear when you run the script. This is the message I am talking about. So reading the data is straightforward. So what you do is that now you connected your database in your PHP script, you can read some data from the database using the select statement to send SQL statements to the MySQL server. You use the query method of the PDO object. Okay, what you do, you use this over here. If your SQL statement returns rows of data as a result set, you can capture the data by assigning the result of over here, like this. And of course, the result returned by $con, this thing over here is actually another type of object called a PDO statement object. You can use this object along with the for each loop over here. And this way you are reading the data and handling everything. And this is of what is covered and which is part of this module. Thank you very much.