‫Welcome back.
‫We created our database my underscore quiz underscore db.
‫And we created the table math underscore table.
‫This math underscore table contains seven columns ID question option 123 and four.
‫And the correct option.
‫Now we can insert records.
‫So click on insert I'll select one.
‫This is the ID the question what is the result of five times six.
‫Specify the option one, 30, 35, 25 and 40 and specify the correct option, which is the 30, and
‫click go.
‫Click browse and you can see your database here and the Table Math table.
‫Select Math Table seven columns one record.
‫The first record is what is the result of five times six?
‫And these are the options and the correct option.
‫We need to fetch these questions from the math underscore table into Json response.
‫This is our mission.
‫So for that we need to use an API.
‫I'll create a new text document and I'll name it as my quiz API.
‫I want from you to focus with me.
‫An API application programming interface with a MySQL database refers to a set of rules, protocols,
‫and tools that allow external applications or systems to interact with and access data from a MySQL
‫database.
‫And in our case, we're going to use this API to access the MySQL database from Android application.
‫This enables developers to create, retrieve, update or delete data in the database without direct
‫access to the database.
‫Server APIs provide a structured way for applications to communicate with and manipulate the database,
‫which is particularly useful in web and mobile app development.
‫So I'm going to write codes here in my quiz API dot text in PHP language.
‫I want from you to focus with me.
‫It's very simple and very important.
‫I'll start with PHP, then I'll create con equals to my SQL underscore connect, and I'll specify localhost
‫root, empty string and my quiz underscore db.
‫In PHP, con is a variable holding the connection to the database.
‫So the dollar sign refers that this is a variable.
‫So con is a variable.
‫MySQL underscore connect.
‫This is a function used to create a connection to the MySQL database.
‫It takes four parameters the localhost the host name of the database server, and in this case it's
‫the local machine where the database is hosted.
‫Root the username used to connect to the database server.
‫An empty string.
‫This is where you would typically provide the password for the database user.
‫Since it's an empty string in your code, it suggests that you are using an empty password, which is
‫generally not recommended for production environments.
‫My quiz DB the name of the database you want to connect to.
‫So if we go back this is our database my underscore quiz underscore db.
‫And please guys make sure that you specify it correctly because it's case sensitive.
‫My underscore quiz underscore db.
‫This is how we specify and how to establish the connection to the database.
‫Then I'll specify another variable Stmt statement equals to connect prepare.
‫And here I need to specify the query.
‫Don't worry I'll specify and I'll lecture everything later on.
‫This is the valuable state equals to con.
‫Prepare, prepare.
‫This method prepares an SQL statement for execution.
‫In this code it's preparing a Select statement.
‫This is the statement.
‫Select the statement to retrieve data from the math underscore quiz table.
‫So this is the name of the table I'm using.
‫The select here is the SQL query and the SQL statement selects several columns from the math underscore
‫quiz table, including the question.
‫Option one.
‫Option two.
‫Option three.
‫Option four.
‫Correct underscore option from the math underscore quiz.
‫Make sure guys that you specify them exactly as the name of the columns, and otherwise it will create
‫an error.
‫So ID question option one, option two, option three, option four and correct underscore option.
‫After preparing the SQL statement, you can execute it and retrieve the result using additional MySQL
‫functions.
‫For example, you would use execute method to run the prepared statements and fetch the results.
‫So here I'll make a comment execute and here I'll start by stmt and call the execute function.
‫In the next video we'll continue with the API.