‫Welcome back.
‫We're going to use this API that we created before in order to get the data from database into Json
‫format.
‫So copy this PHP file, make sure that it is of extension PHP file.
‫Go to see.
‫Damp HD docs and create a new folder.
‫I'll name it as quiz, and inside this quiz folder I'll place my quiz API dot php file.
‫Make sure exam docs, quiz and my quiz API dot php.
‫Now turn on exam.
‫Click start start and then open Chrome.
‫Go to localhost.
‫And this is our dashboard.
‫And I'll remove this dashboard here and I'll add quiz.
‫This is the folder.
‫If we click enter we can see that this folder contains my quiz API dot php file.
‫If I click on it or add the extension.
‫My quiz API dot php.
‫PHP file click enter.
‫Then we have this error.
‫Don't worry, I'll show you how to solve the problems step by step.
‫Here we have uncaught Mysqli SQL exception.
‫No connection could be made because the target machine actively refuse it.
‫Since we didn't specify the port name.
‫Here we have port 4306.
‫I open the php file with notepad and here I need to specify the port name.
‫So whenever you encounter such an error, you need to specify the port name here 4306.
‫Make sure to save okay Ctrl S, then refresh and the error is changed to another error.
‫So the first error is solved.
‫There is another error table.
‫My quiz db dot math quiz doesn't exist.
‫Let me see here in the line six.
‫So in the select statement.
‫So go to the select Statement and Math underscore quiz.
‫Let's go to the database my quiz DB.
‫And here the table is called math underscore table and not math underscore quiz.
‫So here I need to change it to math underscore table.
‫Save it ctrl s then refresh.
‫And here we go.
‫There is another error undefined variable question array.
‫Maybe I missed something here in the question array on line 41.
‫Let me go to line 41.
‫And questions array okay.
‫You see I missed letter S Ctrl S to save then refresh.
‫And here we go.
‫This is our Json response.
‫You can see it starts with an array.
‫And then this is our first object question.
‫Option one.
‫Option two.
‫Option three option four and correct option.
‫Congratulations guys.
‫We fetch it the database data into Json response.
‫Again let's go to here and I'll add another row.
‫So I'll select math Table Insert.
‫And here I'll add the question.
‫And the correct answer is 81.
‫Click Go Browse and you can see this is the second question.
‫Then let's go back to here refresh.
‫And you can see it's a second Json object added here.
‫This is the first question.
‫You can see the comma and the second question.