 In the last video, we were able to query our API and actually get back our account balance. So I'm just going to change this function, call it just a get account balance, that's what I'll just change it to make it more understandable. And now today we're going to be creating our custom database. So what I'm going to do is I actually add a new file here and I'll call it sms database manager PHP. And this is where we shall be adding all our database stuff. So the first thing that I will do is come back here and then I will require it in our files. The next thing I'm going to do is in our activation hook, usually this is where we add, we add our database as we activate the plugin. But I also noticed that we're adding our admin user role inside this particular function. So what I'm going to do is I'm going to create a new function and then within this function, I'll add the function of just adding the sms admin role. But I also add the function of actually us creating a new database. So let me just do that in our page here. So I'm going to add a function and I'm going to call it activation initial functions. So in those functions, I'm going to ask for the function of register their role. So I'll just run it directly here. I'm going to have a function here that I'm going to call create balance database. I'll just call this sms. I'm going to call this before the sms role manager. So I'll save this and then what I'm going to do is copy this. And then I'll add it to our activation hook here. So this function here will run the create database and it will create the add user role in the same goal. So I'll just comment this and add a comment run all the needed functions at the plugin activation. And so the first function that I'll add at function one, I'll say create database for storing the account balance. And then I'll do the same second function, function two will be create admin roles sms manager role. So with this documentation, I think we're ready to roll. So what do we need to create our database? First of all, we need to access the WordPress global, which is WP WordPress in short DB database in short. And this is a global that is instantiated when WordPress starts actually kickstart the WordPress class of creating database. It has preparing statements of SQL. It has all the different methods of sanitizing all the databases that and how they should be created. So when we call this global WP DB, it's going to allow us to do a number of things. So first of all, we want to make sure that our table has a prefix similar to the one of that WordPress. So let's look into the database structure. So in here, I'll look at my database and we see that this is how the database of WordPress looks like. And we see when we install the WooCommerce plugin in here, it had its own structure in terms of the tables. So create a variable here and say we want to access the WP DB. And what we want to get from that point is we want to get the prefix. So the prefix is the one that we usually like, for example, this is the one WP underscore is a prefix that we actually have for this particular database. So we get the prefix and what we're going to do is we're going to evaluate data. So meaning we use double quotes and on that I'm going to append and say sms-sms-manager. I can just add a take a press to make it very, very different from all the other databases that might be created by other plugins. So I'll just do this for short. At this point, we require SQL. So the SQL, this requires you to have a little bit of knowledge in terms of SQL. But we're basically going to get a statement in SQL that's going to get our database. So the first thing we do is we create a table. Now that table will require our table name. And that means we're going to be working in that particular table. And in that table, we're going to create a number of fields in it. So first and foremost, a field I would like is actually the ID and we shall make it a medium integer. So medium int for short. And we shall say let it be nine characters long. Then we shall say it shouldn't be null. At any one time it shouldn't be null. It should never be empty. And then we are going to auto increment it. So every time we create a new line of data inside this table, we'll have the ID automatically incremented and it's going to be automatically filled. So the one thing that I'd also like to have is the time. And this will be a type of data time. And we want it to be with a default time structure of the date, the month and then the year. I want to do the time should also be there. Our minute and seconds. And then at the end we should say it should never be empty. So we add not null to it. And then we add the name. We'll save it as a tiny text. And then it should also not be empty. So it should not be null. We're going to change this and call it balance. Because that's what we want to have. We want to have a balance at the end of the day. For now that would make sense. So what we're going to do next is we're going to have a primary ID, a primary key, sorry. And then in our primary key what we'll choose to have as a primary key will be the ID. And every data this needs a primary key. So we also need one also. So we're going to need character set. So we will have a char set. We're going to save this as a variable. And just like we did with our table name. So let's have this variable where we're getting the database character call it. And we're going to say let's get the wpdb. And on this function we're going to get the get char set call it. So we're going to get the character set on the database. So we use this inbuilt function on WordPress by accessing the global which is wpdb. And then having this function in that class. And I'm just going to remove all this white space. We have finished our SQL. So we're going to require once a file that's very important. And we get it by adding apps path then dot. And then we're going to require this from our WordPress. We'll go for the admin. And then we shall include. I'll go for includes. And then we shall go for upgrade dot PHP. And this file is the one that allows us to do the database upgrades and adding information. So in after accessing this file we're going to go for a particular function which is a db delta. And this one allows us to modify our database by adding SQL. And so in this function we're going to pass one parameter which is needed and which is the SQL statement as we have here. So once I save this we are ready to go. So let me go back to our plugin and then I'm going to deactivate this. And then I'm going to activate it again. So let's see if we created our database table. So when we refresh this page I expect to have WPT press manager in here. So we have managed to create our table in here but I don't like the way it looks. So I'm going to stretch it out a bit. Let me first drop this particular table. So I'm going to drop it and I will change it a little bit. So we have T press, let me do this. Separate the words, save this, go back to the same thing, deactivate, activate, reload. And we have our WordPress T press SMS manager. Very good. So when we come in here we'll see that we have three fields. We have the ID, we have the time and we have the balance. So we are ready to actually insert our data inside our database.