PHP API development | Abdulsamad Aliyu | Skillshare
Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
20 Lessons (2h 41m)
    • 1. Introduction

      4:33
    • 2. What are apis?

      3:15
    • 3. Install Postman

      4:34
    • 4. Install Visual Studio Code

      3:08
    • 5. Install Remote Developer plugin

      2:02
    • 6. Create Google Cloud account

      6:44
    • 7. Create Virtual Machine instance

      7:19
    • 8. SSH key creation

      8:23
    • 9. Connect to server in terminal using SSH

      3:20
    • 10. SSH connect to server through VS code

      12:10
    • 11. Installing LAMP stack

      9:46
    • 12. Installing PHPmyadmin

      7:30
    • 13. Create database and table

      6:52
    • 14. Setting up a working directory

      8:19
    • 15. Installing SLIM framework

      5:03
    • 16. Test SLIM installation and organise our working directory

      5:15
    • 17. Connect to database using PHP

      7:19
    • 18. User registration function part 1

      15:21
    • 19. User registration function part 2

      21:10
    • 20. Login function

      19:20

About This Class

91c1afa3

This class will teach you how to build a fully working PHP API. 

I have put in a lot of time and effort into making sure that this course follows the up to date and standard methods and technologies like: Google Cloud compute engine, SSH, Linux, PHPmyadmin and others.

In this class, you will learn: 

  • PHP programming language
  • PHP SLIM framework
  • Google Compute Engine
  • Structured Query Language
  • PHP API development

You should definitely take this course if you're a/an:

  • Beginner programmers who want to start backend development
  • Intermediate backend developers who want to sharpen their skills

Transcripts

1. Introduction: Hey, guys, how are you doing? My name is Abdul, and I'm welcome to my course on PHP. FBI development. Um, so a little bit about myself. I'm an 18 year old programmer, and I have been coding for about seven years now. I started with basic coding, like batch and basic and other basic languages, and I went on I quickly went onto web programming, and I have been doing a lot of Web programming over the last five years. I don't love back end Web development in front end web development. And I started I Iost and Andrew Development also a few years ago, about four years ago, and I started with underdevelopment, and I moved on to I is development about two years ago, and I have currently currently using Flutter. I have bean ah, huge evangelist for flutter and not have been, uh, learning flutter to build a lot of cross platform APS. So, um, I wanted to build this course because I really, really wanted to teach how to use, um um back end for to your advantage and how to build PHP ap ice, because they are very useful in any kind of doubt. that year thinking off, be it Web development or mobile development, you can use the PHP a p I for your backhand. And having that knowledge is very, very important and could be very useful. So in this course, I am going to show you firstly, how to, um, download those suffers we're going to be using, like, postman in visual studio code. Then I'm going to show you how the register ah, Google account for the cloud functions of the cloud capabilities for Google Cloud and House years Google compute engine Google Compute engine. I'm going to be, ah showing you how to get the $300 credit for free to use the Google account to use the Google Cloud Compute engine. And then I'm going to show you how to create a Google cloud. Compute engine instance. Ah, that's where we're going to be running our Lennox operating system that is going to show that is going to be hosting our a p I. Then I'm going to show you how to use SS H and how to create Ssh Arce keys and I'll be showing you house installed the remote developer visual studio code, which is going to enable us to coat directly on our server using our visual studio coat code editor. Then I'm going to show you how to connect with ssh to our terminal to our Kleenex machine that's hosted in the Google Compute Engine. Then we're going to be installed slim, which is the which is the major framework. We're going to reason this course to build our AP eyes and will install the lamp stack, the Lennox Apache, um, PHP and my skill stack, and we'll set up our database tables and everything. There's a long list, guys, but I will just quickly go over everything. We're going to write the registration function we're going to write, lug and function. We're going to write at posts, function and organs, right, get posts function. So we're basically going to be building like an instagram sort of back end where users will be able to create new accounts and they will be able to lug in, and they're going to be able supposed pictures and get those pictures back. Eso If you're taking this course, I expect you to have a basic understanding of how server works and how the Web works in general and I also expect you to have a basic understanding off the PHP language on. I might be doing a quick I might be adding the Section two this course in the future that is going to introduce you to Ph. B. But as of now, I do not have a section in the course. So I expect you to have a basic understanding of PHP language. Eso Thank you very much for watching the video. I hope you buy this course and I'm going to see you inside the course if you do. Thank you so much. You're supporting me a lot. Ah, I hope you have a nice day and I'll see in the next week. You have a great day. 2. What are apis?: Hey, guys, welcome to another radio, Abdul. Here and in this video I'm going to be giving your brief example or a brief explanation of how AP eyes work. So, firstly, what are AP I the full meaning over a P I is application programming interface and what are they and how they work for that? I found this very amazing block posts that was written by showing up Roman and uh, and opposed to say is what is an A p I. What exactly is an A P I A p I stands for application programming interface and a P I, the software intermediary that allows to applications to talk to each other. In other words and a p I is the messenger that delivers you requested provider that you're sending it from and then delivers ponds back to you. So there's a quick diagram of how ah, there's a quick animation of how that process works. So you, as an end user, send request to the server which has which most likely has an A p I running on it and that a p I processes the request you sent to it and pending on what their request is. Maybe you're asking person information from the database and, um, the a p I does some processing and sends their response back to you the end user, which is the front and usually. So I'm gonna link this, um, great article to the course. You're going to see it in the resources section, and you can go and check the whole. I'll recommend you to read the whole block post. It's really informative. And I also found this great diagram that explains how what an A p I is basically so in an A p I. It's usually there is usually a user interface, like a front and where the end user can interact with that front and could be a site, a mobile application or a customer relations management software or anything really that the user can interact with. So the user can read and write information to the A P I, but they can't communicate with the data directly. They have to go through the A p I. So the FBI is like the middle men between the data and the end user so they can read the data, send the request to read the data to the A P I. The a p a. Fresh is the data from the database and sends it back as a response to the user, and they can also send requests to write the data already in the database to the A P I and the AP makes those changes in the database and sometimes the access. Some functions could be right on Lee. So that's what this Iwry hairs for, and some functions could be read only which is what this area is for. So that's the basics of how AP eyes work and, ah, that's basically what AP eyes are. So thank you again for watching this video. I'm going to move onto the next video on Thank you for buying the course if you have already and have a great day. 3. Install Postman: Hey, guys, welcome to another video in the course, and in this video I'll be showing you how to install the basic software's we are going to be using for the course. In this course, we're going to be using postman and visual studio code. Those are the two major suffers were going to be using. So go ahead and open up safari or any browser you have installed. As for me, I prefer is in safari. So open that open. Go to get postman. Don't calm. I have a bit of a slow connection. So Okay, so postman is basically a tool that you used to test your ap eyes incent get or post requests, um, without having to use a front end so you can programmatically send post or yet requests or put requests to an A P i or server. So go ahead and, uh, signing if you have an account or sign up, if you do not, and we'll just go and download, it can't started. And we're gonna click Download where? Using a Mac. So we're going to download it for Mac if use the windows, just go to 32 bit or 64 bit download and that work fine as well. So I'm going to wait for my download to complete and all catching a bit. So my postman has finished downloading and I'm just going to showed and find her and install that. I'm gonna click open so it can trust it. And we're going to move this to the application's folder or postman ones access to control . Find her along, control. Provide access. Understand? Quick. Okay. And postman is installed, so I wouldn't create an account. But if you do not have an account already, you should go ahead and sign up. But I already have one. So I'm going to sign in here. I'm not an enterprise user. Soldiers signing with my e mail and enter your password as well. And click enter incorrect credentials provided. Okay, Okay. Just give me a minute, guys, so I can check the correct credentials. Okay, guys. So it turned out that I didn't register for the normal account I actually signing. Isn't Google some willing to signing is in global again. There's no problem if you want to do it the other way. It's literally the same soldiers signing using Google. You know, and terror, my mil tres Okay, So, um, if you can see this screen that I'm currently on right now, it means you have postman correctly end completely installed. You do not need to do anything more. And this really is already running too long. So I'm just going to cut it here. And we are going to move on to the next video to install visual studio code on dumb. See you guys in the next video. Thank you for buying the course. If you already bought the course in I hope you have a great day by 4. Install Visual Studio Code: Hey, guys, welcome to another video in the PHP ap I development course on dumb. In this video, I'm going to be showing you how to install, um, visual studio code, which is the I d e or the court endeavor we're going to be using in this course. So go ahead and open up safari, or whichever. What browser you have on your computer and actually easing officials to your code is preferential. It's my personal preference. Is I? I love visual zero code, but you can't use any, um, any idea or a code editor you have on your machine. So who hadn't just called Google Have a bit of a slow connection. And I'm talking very lightly because it's solely here and everyone is sleeping. So period me. It's a search for visual studio code. And, uh, the addresses coat that visual studio dot com. So click on that and open it. Okay. And then, if you are windows, it's gonna say dollar for windows here. Sorry. My always cracking up because they don't know for windows if you're on windows, But I'm on mac, so it's down low for Mac, and I'm going to click that to download officials to be a code, actually, already have it installed on my computer. But I'm still gonna download it just to show you guys and yeah, already started downloading. So I'm going to see you guys when but download is done. And, um yeah, see, on the other side. So my download is almost finished, and it just finished, actually, So it decompressed it, and I'm going to show that in the folder. Open it up, and I It's not from its from the internet. You sure you want to open it? Yes. I'm going to open that. And, uh, groups annoys already have visual studio code installed. As I said for the Windows user, it's quite explanatory for the installation process. You're just gonna click a few next buttons. And for Mac users, you're just going to drag it to the application's folder. So I already have visuals too young installed, so that wouldn't be a problem for me. And, ah, we're going to moving on to the next video. So again, if you have bought the scores, thank you so much for buying the course. You have really supported me and my family, and I appreciate that. Thank you so much for watching this video and all seeing the next one, I think you have a great day. 5. Install Remote Developer plugin: Hey, guys, welcome to another video. It's upto and welcome Teoh. Another video in the PHP a PR development course. So in the last video, we, um, created new ssh keys and re added that toe a virtual mission Instance. And in this video, we are actually going to be, um, adding a new extension to visual studio code. So corps had an open up visual studio code, so I already have a project open. I'm just gonna create a new file. Yes. So we have that open and go to this extensions section over here, click on it and search for remote. So the first package you see the remote dash Ssh. That is a package going to install. So what this package does is it lets you connect through ssh lets you connect to any instance or any Ah, um, any virtual machine that you have running in the cloud through its I p address and you can directly at it the fouls on your I. D. It's amazing. So you guys can go ahead and stall the remote Ssh! Package already have it installed. And, um, yeah, that's going to be for this video and basically like a Let me show you how it works. You can When you quicken f one, it's going to show the command pallets and off for the recently used You can see after remote. Ssh. Connect to host So you can click that and you can try to connect to, um, the ssh host. So that is going to be it for this view. Thank you for watching until the end. Um, I'll see in the next video have a great day. 6. Create Google Cloud account: Hey, guys, it's a door here and welcome to another video in the, uh pH. B A P I development course. And in this video, I'm going to be showing you how to create Google Cloud Compute Engine account, and I'm going to be explaining what that is. So go ahead and open off safari or in the Web browser you have and co two cloud doug google dot com slash compute So Google Cloud Compute engine is just one off the Google Cloud products that, um, specifically, the compute engine allows you to create instances virtual machine instances that allow you to do anything basically so you can create a Windows virtual machine. You can create a, um, a clinics virtual machine that runs on the cloud, and you can excess any time you want. So that's basically what goal crowd cloud compute engine allows you to do. So I'm just look out of my account, actually, and so we can start all over because I already have an account locked in. So yep, we're gonna wait on those two complete. Okay, So this is the screen or does the page you'll find when you go to a cloud aka Goto com slash computer. So it's going to show you the features. It has high performance and scalable V EMS. So the scalability is also one of the reasons that, um, Google Cloud Compute engine has an edge over others. It is easily scalable. So you do not need to by other servers or anything like that. If you want to kill your virtual machine, you basically pay as you go and increase to whatever amount of resources that you need. They have very good prices. And as I took, what do you have access to $300 of credit when you first register. It is low cost fast and efficient, so you can't go through the whole page. She wanted to see the, um, features that compute engine has. But I'm not going to be going through everything because of our time. I wouldn't like to waste your time to go through everything. So go ahead and click. Get started for free. And if you already have ah, Google account, you can already log into this. But if you do not have ah Google account that you can use, you can create a new Google account. But I already have multiple Google accounts, as you can see. So I'm just gonna choose one that off? No, Really used to, um, do Google cloud products compute engine so that I can start from fresh and you can, um, see how everything was. So it's logging me into the platform. Okay, so I'm going to do some set up that Ah, I have done previously. So here's the $300 credit for free they can use and gold cloud products sign up and get $300 to spend on go cloud platform over the next 12 months. So my country is Nigeria. I have read and agree to the terms and condition. Course, if you have time to go ahead and read that have written agree to that free trial in terms of services. Also, I'm gonna agree and continue. That's gonna take a little while to load. But, uh yep. So the step to used to enter your home customer information. Ah, business name. Whatever. Let's say you to me. Course. Uh, name up those Samant all you of kohsh Nicosia. Marcin city as left kosher. Still cold line line. Actually, I forgot to put in my nature and address. Stay quarters our cities. Vida postal code is 912101 And my state is Ah, *** State. That's where I grew up, By the way, that's where my whole family is. So it's *** state. And, uh, yeah, is my primary contact monthly automatic payments? You can leave that, as is to pay to, say, your payment details. And, um, actually, I am gonna grab my credit card for this. Ah, so I'm just gonna cut to where I've already entered. In my credit card information, you need to enter your credit card information so you can set up Billy so you can get the $300 credit. But, ah, they won't charge. So I'm gonna skip to when I've already done all this. So So I already set up the and Google Cloud platform. The compute engine of entered my billing information. So I have gone ahead and, uh, entered my billing information, and it has had building set up for this account. And so it's just going to get compute engine ready. This may take some minutes, annoys That's going to be it for this video in the next video and going to show you how toe create VM version machine is instances for compute engine. So again, thank you for watching this video, and I really appreciate it if you actually purchased this course and thank you for watching the video tilting and I'll see in the next video have a great day. 7. Create Virtual Machine instance: Hey, guys, it's Abdul here. And welcome to another video in the PHP ap I development course. And in this video, I'm going to be showing you how to create your own. Hey, guys, Sorry for the interruption. My laptop went completely haywire. So as I was saying in this video, I'm going to be showing you how to create your own virtual machine instance from Google Cloud Compute engine. So go ahead and open up your browser and we're going to go to the cloud. I thought, google dot com slash compute in a way for that to load and then I'll just go to the consultant. I assume your luck didn't already. So you can just click, go to console and it takes it to the console. So will weigh a bid for it to load. Okay, so there ago we're in the compute engine console and you can go ahead and click on the Via missed instances. Currently, we have no virtual machine instance, so we can create a new one or import or take the quick start guide, and actually, before that, I am going to go ahead and activate this $300 um, credit So we're going to upgrade the account two billion account. You won't be charged until after your free credit are done. So yeah, we are going to refresh now, so it's gonna take effect. So we can either create a new virtual mission assistants or import one we already have or take the quick start. So I'm going to create a new virtual machine instance in the I am going to call. Actually, you have to associate it to a project. Currently, I do have, ah, the project default project. My first project open. But you can create a new project if you want, So we're going to name the instance. And let's call this A P I or PHP a P. I instance dot The region is your central Iowa are goingto leave the region and zone as this. And, um, we're going to live all the settings, as is, I think there. Okay, so you have $300 free trial credits remaining $24.67 mostly estimate. That's about 0.34 hours. Harley dollars. How early? So pay for what you use. No offering costs, which is great in the will need one CP. Actually, we don't need that much memory either. So 3.75 is good. Um, the container option is if you want to deploy container to or an image to the virtual machine instance which we do not want to do. So we're going to leave that unchecked. And, uh, so where this part is actually really important. So that's where we're going to choose the operating system. Want to install on this virtual machine? So we're going to change that. We're going click change. So it's going to load a screen where you can choose an operating system, And for this course, we are going to be using the baboon to 16 points or for LTs Ah. So we're just going to choose that, um, and has a lot of advantages. It is the best war. The implication that I I want to use it for So we're just gonna choose that and click on select. And it has changed that for us. So for the access scopes, we're gonna click, allow, allow default settings, which is okay, And for the firewall, we're just gonna let it allow http and https traffic, and, um, also we have lots doing the management tap owes security tab rather with es ssh. Keys. But we are going to be doing that another time, Not today. So we're just going to live that empty as it is, and we are going to click on create. So it's going to create our instance. And we have our first instance created from ah grew Cloud Compute engine. So is going to set the instance. And I'm going to see you when it's done setting that up. Okay, so it's done setting you up and ah, this is the external I p address for our, um ap I instance or are virtual mission instance And we can connect to it in many different ways multiple different ways. So the most convenient right now is ah, opening it in a browser of winder in the browser window. So we're just gonna click that and it's going to open up our, um, a virtual machine Instance. So right now what is happening is you have a Linux virtual Mission Olympics mission basically in the cloud that you can excess anywhere, any time, and you can access any Montel resource is you want from it or skillet to however big you want it to be. You just have to pay more for it. So ah, it has gone ahead and load it are Instance. So we have here. We currently have nothing in the instance. So we're gonna click unless early in typing Ellis, which is just list the items in the directory and apparently have nothing in it. So we can try quick commands like and Kate tr test, So yeah, unless, as you can see, we have a test fall. Ah, test folder right now. So that's basically you've set up your first virtual machine. Instance running you boon to 16.4 And ah, that's it for this video I am going to see in the next video. If you've paid for this course, I really appreciate you. Thank you so much. And thank you for watching till the end of the video. I'll see in the next time have a great day 8. SSH key creation: Hey, guys, I hope you're having a great day. It's Abdul here. And welcome to another video in the Ph. B. P I development course. And in this video, I'm going to be showing you how to create ssh keys. So in ssh key is very important to be able to connect with your virtual machine using ssh. So basically, when you create an ssh key, it creates a public, creates a public key and a private key Private keys private to you Never share that on a public. He is key that you provide to a platform like Google Cloud Platform that lets you identify your private key whenever you're trying to connect to wonder if that makes sense. But I'm going to link to some resources to learn more about ssh in the resources section. So, um, without further ado, we'll get into the video. So open up your terminal. Uh, we're open up a new tab in terminal. Just close up these ones. So I'm going to seating to the default directory and, um, to create an ssh key. We're going to use the commence. Let me just increase the size a bit. So we're going to use the command s s H key, Jen, and we're going to use the hyphen. See dash C or whatever to specify the user name to attach to our ssh key. So in this case, we're going to be used in the user name off our email address. So I have the email address. Nitric odor was taken at gmail dot com. So I'm going to be using the user name as, um, night recorder was taken, so I'm just gonna type in nitric odor was taken as the user name. So this dash C is just to specify the user name to use at the end of that as this h file. Okay, so the problem were actually having was that? Ah, the C wasn't small case, lower case. So when he chained out to upper case So I'm just going to talk to command again. Ssh. Key. Jen, dash Capital C and these air name will be natural cold. Her was taken. Someone press enter, and it's going to ask me to enter the file to save the key in. Oh, my God. My computer's bugging out. So we are going to open up our terminal and we're let me just increase, not size. So we are going to generate an ssh key for the user name off our email address that's connected to the Google Cloud Products Compute engine. So the command for that is as s h a dash key, Jen, and we're gonna add a flag off, see which is specified. The easier name Miser. Name is nitro cold. Her was taken. So it's gonna ask us the file to save the key. So for mine, I'm just gonna, in turn, natural. And it's gonna ask you for a pass phrase for the key so you can leave that empty if you don't wanna pass race. But I'm gonna pass phrase my own. So it has created the, um, key. It has created the ssh key. So that's s h so we can see the into Dutch. Ssh! To see So, guys, we're going to see d is gonna closed this. So we are going to see d into the ssh folder, and we're going to click ls. And, uh, unfortunately, we do not have our, uh, nearly created Oh, was it cold? Ssh! Fall here. So I'm just gonna find out where that is. Ah, so I don't know why that happened, but we're gonna created a king and named as Nitro. Same past race, same past race. Okay, Okay, so we do have that right now. And, Teoh, check our public fall for the nearly created Ssh key. We're just going to use C 89 troll dot pops. So you see two new files Natural Nitra top Pop Nitro is the private key on nitrogen. Pub is the public key. So this is our key are ssh key. So we are going to at that ssh key to our console at school Cloud to compute engine. So we're going to add it to the virtual machine. Instance. So it knows that it is us when we're trying to connect to it with our ssh. So I'm just going to go see the panel here, and we're going to goes the compute engine and R V M instances. And don't worry about this. Just ignore that. Uh, So we are going to quick on this on the instance, and it's going to load the details for the instance, and we're going to click on at it. So we are going to go down Firstly, very important thing is we're going to check this Enable connecting two serial ports button where Going to check that and make sure it's checked. And then the next thing we're going to do is go down to ssh keys where it stays. Ssh. Keys. Currently, you have your ssh keys, which is accurate. We do not have any ssh keys attached to our vm instance. So we're going to click, show an edit, and we're going to go back to our terminal and copy everything that we got from that result off the, um off their command and we're going to compete are clipboard. Go over here and paste it so it automatically ah, recognizes the user name that we have used for our ssh keys. So we can live everything else as is and click safe. Okay, so that is it. And ah, that's everything. For this video, we have our, um PHP pr instance, our compute engine virtual mission. Instance we have it storing our, um ssh key. So right? No, she'll be able to control that from anywhere that we have. That private s h he. So thank you for watching this video till the end. And I'm going to be seen you in the next video. Have a great day 9. Connect to server in terminal using SSH: Hey, guys. Tiptoe and welcomes another video in the Petri pair development course. And in this video, I am going to be showing you how to, um, connect to your host. Connect to your instance. Fear. Um ssh in the terminal. So we are Let me close up the terminal and start from scratch. So we're going to open up our terminal, and I actually like to do this in the SS ation directly on directory. So I'm just increased at a bit on Let's CD into the don't ask to say shoulder, so OK, so how we connect to our instance is we first Stipe the command Ssh! And then we type I as the flag we passing I as a flag, which is to basically specify the private key that we're going to be using to connect to this instance. So the private you're going to be using his nitro is already in the folder. So we're just gonna entered as is and then next and we're going to do is will enter the user name that we created with all our ssh key, and we're going to add an at and then we're going to add the's external i p address to the end of it. So I'm sure what I mean For me, the user name was 19. Coder was taken, and we're going to I didn't At 34 not $67. 116 No. 235 That's the I P address. So we're going to, uh so currently doesn't have this host stored in list of hosts. So it's asking us if we want to connect if want to continue connecting. So I'm just gonna reply with yes and enter. So it permanently added that to the list of hosts. And then I'm going to add Enter the past phrase that I entered when I was creating the ssh key, which for me, I did enter a pass phrase. But if you didn't enter a pass raced and he can just go ahead and press enter. So that is it. And as you can see, we have easily connected to our as ah to our Ph. B p. I instance. And to prove this to you that were actually connected to the instance in our terminal veer via ssh, I am just come to a less if you can remember from the last Fyvie deals. We actually created a folder called Test. So if I type in ls we should see that folder in here right now. So test, as you can see, we have ah heart instance connected and congratulations. You just created your first virtual mission. Instance And you just connected to it. Fe. Ssh! And that's going to be a for this section in this video. Thank you for buying the course. And thank you for watching the video till the end. I am going to see you in the next video. Have a great day. 10. SSH connect to server through VS code: guys. It's upto and Wilkinson. Other video in the PHP Pierre Development course not before I start this video. I just wanted to share a quick story that I found really funny. So you have few of you have noticed, like in the past few videos. My keyboard was sort of acting out, and, uh, I was restarting my Mac book like, five times I I was just freaking out because I just bought this man in what it costs a lot of money. So I I later found out I had connected the receiver for my Bluetooth keyboard issue the computer. I left it connected, and I left the key work on the bed. Me and my brother shared the same bed, and as you can see, it's currently once before. And so he was on the bed and he moved over the keyboard, so his hands were on the Q board. They were pressing random like characters so that I had a massive panic. Like I thought my black work you board was breaking. I didn't know what to do, but it turned out it was just my years be wireless keyboard that was being press. Anyways, that's not for the funny story In this video, I'm going to be showing you how to connect your instance. My, um, via the last video, I shouldn't have to connect to the virtual machine. Instance in your terminal via Ssh. And in this video, I'm going to show you how to connect to the virtual machine. Instance via visual studio code directly so you can add a coat from there directly. So to do that izing you've already had the package installed for remote sessions. And before that, you can just go back and connect a sensation. Your terminal. I'm actually going to city into this test folder, and we're just gonna create an index dot PHP uh, working a touch index stop PHP. So we're just gonna create that file, and that's so we can edit it. And we can also, you know, create new fouls from our visual studio code. So I'm going to press path one, and it's going to show me the command, so I'm going to connect to host. So for this, we need a private key, right? So and it's not going to let us do it directly from the commence, or at least I do not know the command to do that directly. So I'm going to show you a pretty neat trick. You could click on config, configure ssh hosts, and then you're going to choose to configure it. This ssh host. So it is going to went up a new cook thick file. So I already have the template for that open here. So we're just gonna copy this? If you need the link, I'll leave it in the resources. So we'll just copy this and paste it into our config file. The host is the I. P. Address off our virtual machine. Instance, she's 34 dots. 67.11 62 35 So so you for 67 Don't want 16 to 3 college. While I hope I got there correctly. Yes, I did. And the user is your user name on that host. So monkeys her name is Nitra. Colder was taken. And the host name, uh, let's just say let's name it Ph B p. I say miles or instance a fish B A p. I instance I don't know if you guys can't see this clearly, so I'm just gonna increase. Yeah, is much better. So host and the user name and then the host name. So now the identity filed Use our chance to be able to specify the private you were going to be, isn't it? And in our case, prive accused dot s s h slash are my shroh. So we're going to save that and you can go ahead and close it and quick f reneging and connect to essay shows so we can quit this holds to connect to and it opens up a new window . So it's saying it could not resolve host name. So let's just close that. Try to fix what is going on that's changed the situation to be resolve hosts thing. Just a minute, guys. Okay, guys, my bat. So, uh, actually, the host name is going to be the I. P address. I'm so sorry for that. Let's just piece that here in the host is going to be the name off the host itself. So work on two Peace that there's all save it. We're going to repeat the procedure F one connect to host and the young ph PPE instance. Fingers crossed that work. Now that works now, so the past freeze for the key were ago. Genter to pass race for the key. Ah, yeah, And we're going to wait for it to set up the A sage hosts. And that's my dog. Oh, playing about I don't know. It seems that we're currently connected to the exactly. So we're connected. Toothy, ssh. Were connected to the virtual machine instance. Assess age successfully and ah, to prove that which, in open a folder, uh, whole mantra colder was taken. We have test folder, We can't open that. And just quick. Okay, so it's going to open a new window for that. Her very slow connection. That's why it's taking a long time. But it should take this much time. Minorities. Okay, so we're connected to, uh, the host machine and we are in index PHP right now. So we are. Let's just create a simple PHP fall hp, and it's cool. Hello, World Classic, right? So, yeah, I have my syntax highlighting back. So we're going to save that And to prove to you that this is actually our AP i instance our virtual mission Instance. I'm just gonna go back to my, uh it's called my terminal Where have it connected? Ssh! So I'm going to go back to that. And I am going Teoh Unless a cane. So we have in next PHP, Uh, and that is working or have very slow Internet. Oh, my God, What's going on? The Internet is really so I don't think it's even working. I'm just gonna close that. And before I cool there, let's even create a new fall here. Let's create tests, not Ph. B. And the 90 reflects on our ssh connection. Oh, my God, apparently I don't even have Internet. Really? Okay, so test up PHP has been created and let's discreet another small PHP Fall day echoes what's going on today? My internet is really crappy. Guys, I'm just gonna pause it and try to resolve that and all continue the video. Okay, Maybe I don't want you to pause. Anyways, let's quickly get this done and we're gonna echo. This is a test country, and we're going to see that. Yes, and we're going to connect to the for instance. It came so Listrik keep your dress done going to ssh into it as a sage. Hi. And we're going to specify the private Key, which is on Nitro in the user name Nitra. Coulter was taken at three for about 67 thirties offscreen 67 not 116 start to 35 And we're going to connect to that. Yep, and it automatically connected, since it's so config fall. So let's LS and CD into tests and the step and she can see no have or test that PHP fall. And we also have our old index stop PHP fall and used Dannell to check them just to verify that we were indeed connected toe our host machine. So now no index dot PHP and you can see we have you next on PHP file that we created and edited. So to exit out of Nano, just Click Control X. And yet it's gonna edit. Let's also no no into tests dot PHP and you can see this is test stop does test PHP. So that's going to be if for this video, we have been able to successfully connect our virtual machine instance to our visual studio code so we can directly edit code in our idea of choice. I'm using visual studio code because I prefer, and it's actually a really, really good idea. But if you're using another I d like Adam. I can't imagine therapy a package for you that you can't used to connect the h ssh hosts. So, um yeah, that's going to be it for this video. Thank you for watch until the end. I think it was a really long one. Thank you for watching till the end. And I'm going to see in the next video have a great day. 11. Installing LAMP stack: Hello, guys. Hard doing Welcome to another video, Abdul. Here and in this video, I am going to be showing you how to install the lamp stack on are open to server. The lamp stack is basically standing for Lennox Apache, my SQL and ph. B. So we're going to be installing those things in our, um, open to server eso First things first, open up your terminal and well connected s age to our, um, server are a boon to server. So, uhm, I'm going to see dean to dot ssh. And, um since we already have a config foul, we can just s S h that config foul. We don't need to enter. Um, anything else? Um, one minute. Okay, guys. So I quickly checked the flag to get our config file. So it turns out we're going to ssh dash um, f capital F. And we're going to specify our config fell in my case. That's config. And ah, what is going on? Ssh Dash, If config Oh, yeah. I would still have to, um, use our i p address for the, um for the linen. Um, a p i instance. So I'll go ahead and check my I p address. We're here. Ah, just a minute. So our i p address is, um 34 not 67 It's very lights, So r I P addresses. Ssh! We're just going to type in. Ssh! Dash f config. $34.67. 116.235 Okay, You know what, guys? I'm just going to connect to the SS age the way we usually do in the terminal. So let me just increase the size of this of it, and we're going to ssh dash I and will specify are, um, private fall off Private key, which is not a troll and will specify the user name at the I P address. So Nitro Coder was taken at 34.67 dot 116.235 And we're going to enter the past phrase for our private key and were connected. Hurry. So first thing first to do when we want to install the lamp stack is we're going to install while we're going to install limits, which we already did when we're setting up our virtual machine. Instance. So the next thing we're going to do is to install Apache. And Apache is basically a Web server that can run on Lennox. And you can access the i p address from anywhere on the web and put 1000 that Web server so you can access them anywhere. Really? So, um, to install Apache. Always. There is pseudo a p t install Apache two. Yes, we want to continue. So I'm gonna wait for two complete downloading. So Apache has finished downloading. Okay, so yep, it has finished downloading. And, um, there's something fun that I wanted to try out. I saw it on instagram a few days ago. So if you guys 12 you can try it out with me. Just type in the command alias, please equals quotes, pseudo. So basically is going to change the ah command pseudo to please. You can still use pseudo, but like you can also use please. So the next thing we're going to do is install my SQL, which SQL stands for structured query language, and we're going to install of the SQL Server, which is basically the server which is going to run our database, our SQL database. So, gonna typing, please. A pc in stone my SQL server. And yes, we want to continue this operation. I hope you guys can see the terminal because my text are a little bit too small. I hope you can see them now. And I am going to wait for that to install a swell. Okay, So it brought me to the screen where it's going to ask for the password for the root user off the, um of the my SQL your pH remind mean whatever but the password just entering any password that you're sure you're going to remember. So asking to repeat the past word, I'm going to repeat the password. And ah, my school server is almost don't setting up now. And with the power of editing, I'm going see you and it's done. Great. So we have my SQL server set up correctly now. So the next thing we're going to do is to install PHP and for that we're going to typing. Please. Ap ti install PHP dash pierre PHP dash f p m. So these are the packages required to make PHP work. Ah, properly So go ahead and run that command. And yes, we want to continue. And this shouldn't take really long. Okay, so we have PHP properly installed. So the next step in installing our lamp stack is to restart the Apache server and to restart the Apache server or just going to run this command, please. Service Apache two, restart. Great. So if you don't see anything, it means you're Apaches. Restored it. Your Apache servers restarted. So we are going to test this out right now in ah, browser. Any browser of your choice currently have safari open. So I'm just gonna drag a window over here, and ah, we're going to type in the, um the i p address of our server. So we're going to tie pain. Http. Ah, 34.67 dot 116.235 Okay, so if you are brought to this page where it says a party to go into default page, it means you have correctly set up Apache congratulations, and you have set up your lamp stack. So the next thing we're going to do is to test our PHP. And for that, we are going to go zoop. PHP Oh, are echo max slash and backslash. Um, your PHP in stone post sorry. Uh, let's just go back to that command and let's is complete so you can see it printed out in the terminal. Your PHP install these complete. So, congratulations. You have PHP correctly installed, and, um, that will be basically it for this video. Thank you so much for watching until the end. And I'll see you in the next video. Have a great day. 12. Installing PHPmyadmin: Hello, guys. Are you all doing? Welcome to another video. It's Abdul here. And in this video I am going to be showing you how to install PHP my admin on your Maya skill server. So I already have my ssh. I've already logged in with as sage in the terminal. If you have not done so, go ahead and use ssh to log into your server. So for, um, one to install pH we mired mean? We just need a simple command, which is a p t. Please, If you haven't done this, please thing it's OK. You don't have to do it. It's just fun. Please ap ti gets install PHP my admin. So, yes, we want to continue and it's going to ask us for ah, Web server to reconfigure automatically using Apache two. So we're gonna continue with that by pressing enter. It's gonna take a while. So the PHP mind man package must have database installed and configured before it can be used. This can be optionally handled with d become fit Common. If you are in advanced database administrator and you want to perform the configuration manually, manually or if your database has already being installed and configured. You should refuse this option. Details on what needs to be done should most likely be provided in blah, blah, blah. Otherwise, you should proceed to choose this option. Configure database for ph in mind. Mood did become thick common since we haven't created a database earlier parts now. So we're just gonna entered for yes, and it's asking for the past word for my SQL. So we're gonna enter the password, and we're gonna confirm password. Great. So we have PHP my admin installed right now, so, uh, we are going to test it out. So, uh, before we test it, we're going to restart the A patch server, so that will be pleased. Service Apache two, restart. Okay, so we're going to test it one more time, and it's still not working. I have it testing on my other screened, by the way. So I'll try to figure out what's going on with it, and, um t I'll try to figure out what's going on with Appeared to be my admin, and I'll get back to you guys. So, um, I found this fixed, and we should try, So the first thing is ah, you'll type the command, please. Ellen, with a flag. Ass slash e T c slash PHP my admin slash Apache dot com slash e t c slash e T c slash Apache two slash con of a level slash PHP My admin. No cons. I know that is a long line, but just type it exactly as it is, then the next command is pleased. A to e n con PHP my admin not called. Okay. So to activate the new configuration, you need to run service. Apaches who reload. So service Apache two reload. Okay, so you are going to enter the password. Oh, wow. Let's just add the please command before that. Okay? So it has reloaded the Apache two, and, um, right now, Well, what's going on? Night PHP. My admin. Okay, so it seems to just be loading the, um, cold. Not the Apache Petri mired Min itself. So we're going to try to fix that right now, so it looks like our PHP isn't configured, um, correctly. So we are going to try to fix it. Is in some commands here. Pseudo a to e n mod proxy. Underscore f c g i, and do not worry a lot about these commands. I also just check them from the Internet. So set em que pseudo a to e n con PHP seven point zero f p m so pseudo service Apache two restore. So there you go. We have our pH be installed correctly now, and, um, we have our Apache. Ah ph you mired mean also installed correctly. So let's just go ahead and log in with I think the user name shall be route and ah, yeah, the password shall be the password that you said. So, yeah, that is that we have our default table's already created, and now we can create a new table using the new button. But that is going to be it for this video. I'll show you all that on how to create your own tables and ah, your own database in the next video. So thank you for watching this whole video. Ah, I appreciate you for buying the course. I'll see in the next video. Have a great day 13. Create database and table: Hello, guys. Welcome to another video in the course on PHP. FBI development using Slim and Google compute engine VM instances. So in this video, we're going to be creating our database. In the last video, we set up our PHP my ad mean so in this video, we're going to be set in all part database and creating the tables. So I have ah, open a safari tap, and I'm just gonna go to compute engine. Okay, so we have our PHP ap I instance, open up, and, um, Teoh set up our database. Um, I'm going to open a new tab and go over to that. Ah, I p address 34.67 que 34.6 exactly. And, um PHP my admin. Okay, so, uh, hopefully I get the password. Okay, so we're in. So the first thing we're going to do is to create our database and, um, to create our database will go to this new button over here, and we'll just name it. Ah, PHP a p I and click enter. So we have or database created and, um will have ah list of tables to create. Also in this video so Ah, I'll go ahead and just check that list of table right now. So actually, for this course, we're going to be creating just one tape, which is just a least of the users that are on our app. And I'm sorry, guys. If my voice sounds weird, I'm a bit sick. I've been sick for a few days right now. So, um, let's go ahead and create a new table. We find this. Okay, Let me just go to the database from the beginning. So since we have no table is going to ask us to create a new table, and then it's going to ask for the name of that table and the number of columns you want to use for that table. So a table is basically like a list off your off the data you want to store. So for my SQL, you'll already have, like, a pretty find parameters to put in that list. So that's what a table is. And I'll go ahead and show you guys so we'll name the table users and ah, well, just ask for, let's say, six columns. I don't know if we'll need that many columns, but let's just say six columns. So the first important thing that usually do while creating a table in my SQL is to specify the I D column, which is basically the unique identifier for that roll off your, um, off your list for that roll off the data you want to get, so the type is going to be integer Ah, the length we're just gonna impute 11 and default will live That attribute will live that collision. Leave that. No, no, we do not want it to be No. So we'll leave that unchecked. And, um, ai ai basically stands for auto increment and that is exactly what one for our unique i d field. So when a new data is entered into the database, it automatically increases thieve value off the i. D. Based on what the previous value of the I. D is. So let's check automatically increase. Ah, increment and um will set the index as the primary because it's the primary key for this table. So we'll leave that as is, and we're done with the I. D column right now. So the next column will be our user name, and we'll just make that of arch are so of our char is just ah variable off characters so on. And we're going to make the length to 55 and, um will also make password. We'll make that far char So the password when we're building our ah ph b a p I is going to be encrypted. So the password is going to be storing an encrypted text. Not, ah, just the plain password. So we'll leave that at 2 55 as well. And, um, also have first name, and ah will enter that as of arch are 2 55 and less name Vore Chur and 2 55 Is there anything else we want for? Oh our user? Let's see, Let's enter a short by. Let's give a space for a buy for the user So we'll live that as a var Ciara's well and then , Ah, believe that as a torture and will make the space 500. So we're going to save our table and there we go. We have a table. So to test our table, we're going to go ahead and insert a new ah data, a new data point and for the data we do not need to enter anything in the I d filled because it'll automatically automatically increment. And, um, so it's starting from zero. So implementing that's going to be one. So the user name, let's say Nigel password. Ah, password. Of course. First name Abdel. Last name Julia. I see by just a nice guy. You know, the classic bio on real quick. Go. So one row inserted. Ah, we have successfully inserted data into the database table we just created. So that's going to be for this video. Congratulations. You've created first database and your database table using Google Compute Engine. So thank you for watching this real till the and I am going to see in the next video have a great day. 14. Setting up a working directory: Hello, guys. Welcome to another video in the PHP P I development course I'm Abdul. And ah, I hope youll are having a great day in this video. I'm going to be showing you how to create your first index dot PHP file in the FBI directory. And we're going to be connecting to our, um, virtual machine instance through ssh. Using the terminal and also visual studio coat. So ah, without further do, let's well further do Let's get into it. So I'm going to open up terminal first. Nous closed these tabs open up. Brand new tab. Close this one. So, uh, CD and I'm just gonna seating to dot Ssh. Okay. So Ah, I'm just gonna ssh into the, um i p address. So you know the way we usually doing. Ssh. Dash I three. Um Nitro. My trick order was taken at 34.6 seven 116 not 235 So we're going to enter the past phrase and were successfully connected, so we'll just, uh, cd into slash for slash Dull be doubly w slash html. And this is the default folder for Apache to read from. So, um, we are going to m k d I our to make a new directory and called a P h p Ah. Underscore a p I Okay, permission denied. Ah, thank you. So we're just gonna use pseudo or please as we have made the alias make directory PHP a p I Oh, I think we have to make it again. We didn't had it, Wouldn't added, like, permanently. And it's pretty fun. So I'm just gonna do it again. Que So please make de ir ph b underscore a p I Okay, so we have our PHP ap I let city into Ah PHP the a p i. And let's just make a new, uh, fall cold in the stop. PHP, Please touch index, stop PHP. Okay, so we have That s so the next thing we're going to do is to open up visual studio code. No, in images. Track that over. And actually, before we proceed to this level, let's cd dot dot There some issues with virtual machines in gold compute engine like some permission issues. So what I normally do is just to change the permissions on those files so that I can edit them using, um, visual studio code. And then when I'm done, I changed the permissions back to the way they originally Where? So, ah, for this you could probably use a, uh I say for permission line other than 777 but to just keep it simple, I'm going to change the permissions for that directly directory using please tomato to change the mount. Ah, dash are to make sure it's recursive because we're doing it for a folder or directory. Jamal Dash R seven, 777 and no, it's going to be PHP on the square a p I Okay, so we have that down, we have changed the permissions. So the next thing we're going to do is to press F one in visual studio code and will click on Connect to ssh host. So already have ah PHP ap. I set up in my ssh host configuration. You can watch that video if you missed it or skipped it, showed you how to, you know, create a conflict foul for ah ah ssh. So click that it's going to ask for the past phrase and I'm going to enter through past phrase. Okay, so after that loading up, I'm going to open a folder and, um, way for that. Okay, so the folder I'm going to open up is slash far forward slash www ford slash html. And, uh, let's just open that hole directory. Have a bit of a slow Internet. Uh, so I'm just gonna cut, too. When this lot's okay, it's downloading. So open up our PHP ap I open up index stop PHP in the open up a PHP tags Clues that and we'll just do a simple echo a coal hello world and we'll say that only for two safe. OK, it's done saving. Let's go back to ah Safari. And, um, just copy this i p address and go to a new tab at that i p address and, um, go to PHP slash ford slash PHP underscore a p i and ah slash index dot PHP or you could just live it because it automatically detects index dot PHP. So we have our little world printed. We have our hello world. We have it ah, printed to the browser through our PHP file. So that's it for this video. And the rest of this course actually wouldn't be isn't browser to test we'll be using postman postman to test. And I have shown you how to download and like where to download post men in one of the previous three years. So go ahead and check that out. If in case you missed it so Ah, that's it for this video. Hope you guys have a great day. Thank you for watch until the end. And I'll see you in the next video. 15. Installing SLIM framework: Hello guys are welcome to another video in the PHP ap I development course And I am Abdul Hope you guys are having a great day. And this video I'm going to be showing you guys how to install Slim, which is the framework we're going to be using to build our PHP ap I so Ah, I assume you've already opened up your You've already connected to your virtual machine. Instance using ssh through the terminal eso I already have mine connected so I'm just going to seating to our A P I directory. So it's PHP underscore a p I and ah, we're going to run a command using composer. I'm not sure if we have composer installed, so I'm just going to try it. Then we're gonna install it. I'm not sure if we have composer installed. I'm just gonna Ah, so I'm not sure if we currently have composer installed, so I'm just gonna try installing Slim Ah. Then we'll try and stolen composer if it's not installed. So please composer require slim slash slim. And we're just gonna install, uh, version 3.0. Okay. Composer not found. So let's just run, please. Ap ti in stone. Composer? Yes. Okay, so, um, let's run that command again. The please composer require slim Ford slash slim and just ah, version 3.0 que could not find slim slash slim. Okay, we're gonna fix that in a pit. So we are, um, not see, please. Composer require slim slash slim. Hopefully, it's gonna download the latest version. Okay, so I think, uh, that's properly installed. Yes, and we have slim installed eso we have ah, slim finally installed. So we are going to test it out. This piece of code shoot. Um, if there is no error, it means that we have slim properly installed. So we require vendor slash or the load dot PHP and, um will just create a new slim app. App equals new slim backwards slash backwards slash ap and ah, we'll save that. So we're just including this on load file. And, um, let's open up safari and reload that. Hey, so, index, stop Ph. B. So the thing with like, installing slim is that we Currently it's working. This shows that it's working. So what we need to do is to basically create our functions through the app variable. That we create it. And then we can route those functions to different Urals and then make get and post requests using them. So that's it. We successfully installed Slim and not thank you for watching this video. This is the end of the video and I'll see you in the second part of this. We all see in the next video there is no second part to this video. I'll see you guys in next to you. Thank you for buying the course. Thank you for watch until the end. Hope you have a great day. 16. Test SLIM installation and organise our working directory: Hello, guys. Welcome to another video in the PHP FBI Development course. I'm up Dole, and I hope you're having a great day. So in this video, we're going to be doing a little bit off clean up, so we're going to clean up or working directory. And the first being where going to do is just create a new folder and name that folder public in this folder are indexed. All PHP is gonna be moved there. And, uh, yes. So we have ah, first thing we're going to change in the the next stop. PHP is require vendor auto load. We're going to change that, so dot, dot, Slash To specify that it's in the previous directory. So we're also going to do some other things like or going to import our request. So it's going to be used. Backslash PSR back slash h zp backslash message backslash server request in her face as request and ah, our response as well. We're going to be using backslash PSR backslash http Backslash message. Backslash responds in her face as responds. Okay, so we have that down and ah, we're just gonna go ahead and ah, test are slim implementation So this needs a backslash before the slim. So we're going to do. Told her son app get And not just the default directory, which is ford Slash. And then we're gonna create a callback function for that function. It will take the request as, ah, a za parameters, a request response. First poems. And, uh, we're just gonna add a sample call. Um, and ah, we're gonna return that response. Return response with status 200 and with Jason. Hell, we're and we're going to run the app solidly app running. Okay, so ah, we're going to test that out in post men. Uh, and found found. What's going on? Let's see. Okay, we have our ah, public. We have it in a public directory. So, uh, we're gonna add public, and they're ago. We have for Jason. Returned as hello world. So the next thing that I'm gonna do is ah, I'm going to create a more organized ah file structure or folder structure, and we're going to be creating theme the folder that is gonna connect to our database in the next video. So let's create a folder in PHP ap i called SRC or sources. This just convention. It's my convention off building an A p. I do not have to follow it. So we're going to create a new foul firstly called db handler dot PHP. And then we're going to create a new folder called Con Fig and in that folder will create two new falls. The 1st 1 is Ah, uh, Constand. Stop PHP! And the second foul is a scream. No foul. Second follows DVD dot PHP. So Ah, that's it. That's the basic fall structure. And the convention will be following for this course. So once again, thank you for buying this course and thank you for watching the video till the end. I am going to see in the next video Have a great day, guys. 17. Connect to database using PHP: Hello, guys. Welcome to another video in the pH. PPL development course. And in this video, we're going to set up our connection with our database. So, uh, first things first is ah, let's just take care of the common files. This constant start PHP. I already have a whole file is just a far the list that defines the list off. Um, http status codes and basically defines them as constants. So we're gonna go ahead and create that close the tag, and ah will create a class called Constance. And I'll just cup you over all the constants that I have Ah, from my previous fall and copy them into this one. So, yes, those are the common http status coats that will be needing. And the second thing we're going to take care off is our db dot PHP. So this is going to hold our, um it's going to hold our information to connect or DB. So, uh, that's create the fall ph beam, and we're gonna create a class called DB and, uh, create of private variable called DB host, and we'll set that as local host in another variable cold TB user. And that's just route here. And ah, another variable called TV pass. And that will be PHP underscore a p I in my case. And ah, another cold private TB pass. Ah, sorry. TV name, which is the name over database. And I think we named that PHP p. I is well, but I'm just gonna check it. Okay? We did name it. PHP dash ap I PHP dash a p I Okay, so ah, we're going to create a function called Connect, and the function will be public. So, uh, we're gonna create the function as public function connect No arguments. Uh, create a variable, cold db connection equals new my SQL I and ah, it's going to use this TB host coma this D B user, this DB pass and this d b uh, name. So that is OK, we do don't need that space. Okay, So if, um, my ask you ally connects. Basically, we're checking if the connection failed. Mm. Connect air? No. Which is there is an error number four, the connection filled. So we're going to echo filled to connect to my as que el don't. And we're just gonna contaminate the error coat. Just gonna copy that and paste it over. And Ah, that's it. Now we're going to return the DB connection. If there was, in fact, a connection. Okay, great. So, um, now we'll move over to DB Handler and in DB Handler or just going to create a simple class as well open the PHP tag and closed a PHP tag. We treat the class to be handler and will create a private, viable called con to hold our connection. And we're going to construct this, um, bee handler, construct function, underscore, underscore, construct, and open that up. We're going to require once, so it doesn't require that more than once. Config slash db dot PHP require ones config slash constance The PHP in the d B will be a cool new dp in this the connection variable we created We're going to set that equals d B don't connect. So it's going to call the connect function we created over here in db dot PHP This connect function and is going to set our connect con variable in db handler to the value we get back. So ah, that's pretty much it for, um db Handler. Let's go over to index stop Ph. P. And let's just require that so require. Ah, dot, dot, slash as are c slash convict slash db Top. Oh, sorry. Slash This is gonna be DP handler. PHP. Okay, so, uh, hopefully that works. Let's test it out. Okay, so it seemed that everything has worked and Ah, yeah, Let's, um actually, let's get user. Let's it's getting our, uh, user or never mind. Well, we're going to save that for the next feel. And we're gonna be testing or maybe handler using the next week. You. So thank you for buying this course. Thank you for watching till the end. I'll see in the next video. I hope you have an awesome day. Take care. 18. User registration function part 1: Hello, guys. Welcome to another video in the PHP FBI Development course. It's Abdel here, and I hope you are having a great day. So in this video, I'm going to be showing you how to create our first AP I function, which is the registration function. But before we do that, we're just going to go ahead and create too quick functions. And the 1st 1 is is valid email to validate the email. And, um, the 2nd 1 is to verify the required parameters for each request each post request. So let's go ahead and create. The 1st 1 function is Valley email address, and it will take in the email dress asked e parameter we parameter and ah, if filter var you can use this to, uh, var filters a variable with a specified filter, so ah, it filters a variable with the specified filter. That's exactly what it does. So the trick we're gonna use to make it filter emails is to enter the email and then the filter. We're going to be using his filter underscore validate e mail that comes with PHP. So if that we're going to return true else, actually, Do you know what? We can be more sleek here. Ah, we're gonna use return that I just realized that that called all being one line. Ah, so we're just going to return that and cross our fingers that it works? I hope it works. Uh, actual imagery documentation on filter for quickly to see what type of value returns. Uh, so we're gonna check that Open up the PHP manual. Ah. Okay, so it returns the filter data or false if filled her fills. Huh? So, uh, let's just write it the way. Where is before? If that true. Els. Sorry, l So it's gonna return. False. Okay, So, uh, semi colon and all, we're going to move on to writing the next function, which is ah, function. Verify required pair AM's and it's gonna take required fields as Theo. The only parameter. Nah, it's going to be okay. Let's start by creating a new variable. Cold air equals False Zeppelin, and, uh, the error fields equals this and ah, request Haram's equals array. Request Haram's equals underscored request. Ah, that's ah variable provided by PHP as well, which is basically the parameters from any requester sending to your a p I So we're going to do it for each loop. If you don't know what this is, you can check it in the Ph. D. Manu. So we are going to for each request, required fields as field. If not, it's set. Basically, we're just checking if each parameter is not know, like, if each ah, each required parameter is not know. And ah, the the the string length off the parameter is not less than or equal to zero. So basically, if each parameter is an empty so we request on the score Paramus field. Okay. Or S t r l e n to check the stream length in the string length and ah, trim. We're going to trim it to remove any empty space request. Rooms of Field K is not a cool too zero. And ah would just make the error equal truth. Air fields no equals start field. Uh, okay, so ah, we are going to return that error. So it's a boolean function basically, and the next thing we're going to do is to be creating our registration function. So, um, we'll go ahead and change the first. The first ah, what's it called? The first AP, I called to a post request. First, a p I function to post request, and that will be, let's say, new user. And the first thing we're going to do is to get the impute data, which is the ah, the parameters the user passed during the A P I call. So we're going to use impute data equals request the request with passing as a parameter get parsed, buddy. So he's going to get it as Jason, I believe, Jason, if now we're going to check if older required parameters or passed into the, uh into the impute data. So if verify required Paramus in ah, the array or the impute is going to be an array off the parameters we want. So the 1st 1 is user name. 2nd 1 for the registration function is email. 3rd 1 is ah, did we create an email filled in our database? Let me check that right now. Okay. We didn't create an email felt So we're going to go ahead and create that and we'll just add one column after user name and it will be email type is going to be var char. The length will be 500. Let's just keep it at 500 and Ah, yeah, that's basically it created an email filled. So let's go back to our code. And ah, user name email. Ah, passed. Word is also required in the last name. Okay, before last name. That's just enter, uh, first name. And ah, instead, it Let's burrows user name, first name esteem and also bail. So we're gonna require bio parameter is well, bio. So if that is okay verified. Okay. So if that is true, based on our ah implementation of that function, if it is true, it means one or more parameters are missing. So, uh, if that is true, we're going to create a variable cold rest message, which is basically the result message rest MSG, and it's going to be an associative array and the mess age is going to be equal the required parameters or missing. And now we're going to return their response with a status off. And ah, this is where we're going to need a new require meant. So we're going to require dot, dot, slash SRC slash con fig slash Ah, constance dot PHP. So we're going to require the constant so we can get the H http. Status codes. So the first status code we're going to respond with when the required parameters are missing is Constance. Http Status. Bad requests, que and, ah, we're going to return with the Jason rest message. And, uh, we're going to exit and to get out of there. And, um, the next thing we're going to do is to get the, ah information from the user to get the What's it called the, um, the data from the user to get them into their own variables. So the first viable we're going to create is user name. Ah, well being called to impute data Use your name, so I'm just gonna copy that. And ah, paste it. Five times on Tuesday, 345 So the next one is Ah, e mail. Be equal. Teoh mail. Next one will be password equals. Ah, password Done. The next one will be first name Cool's first name in the next room. B last name less name. And the last one will be bio by you. So, um, let's test what we have currently. And, ah, if we do not have the slash new user, if we do not have to required parameters. It should return a bad request. So let's use the buddy and I'll just delete all this. And Ah, here's what I want you to do. When you're testing for this, you have to have your X w w w doff www dash form. That's Ural. Encoded, enabled. And also, if you are making a request room from an app or something, you have to include that in the header that Ah, the type off the body. The body type is going to be this form your l and code it. So let's send the request in, see what we get back. Okay? It's a post requests or chain that supposed. And okay, we get our Jason off the message that required parameters are missing. And ah, when we enter the parameters, it should show us Hello, world. So let's enter those parameters. 1st 1 is user name test. Ah, e mail test and test dot com. Ah, password test Password. Um, first name Abdul s name. Al. You and ah bio should be Hi, guys. Whatever. So let's just send it and ah, we have had a world. It means our code till this point is working. Ah, the next thing we're actually I think this video is running on too long. So in the next part, off this video, I'm going to show you how to complete the registration function. So thank you for watching till the end. I'll see in the next video. 19. User registration function part 2: Hey, guys, welcome to another video. And this video is a continuation of creating the registration function. So in the last video, we got up to here and ran out of time. So in this video, we're going to complete the registration function, so ah, we're going to create in if check to check you for email is valid. So is, if not is valid. Email address through the email. We're going to return your response with status of, uh, Constance. Http. Underscores status. Bad request again. And let's just respond with Jason. Jason off email is invalid. And though we're going to exit the coat, so ah, let's test if that works. Open up, postman. Unless just changed this to test at and send that. Okay, we have email is valued in 400 bad requests as our response sold. Has changed it back and see if it works. Drum roll. Yes, it still works. Glad we didn't break anything, so Ah, the rest of this function is just going to be calling, creating an instance of the database handler, db handler and ah returning. So we're going to be creating an instance off db handler and we're going to McConnell function, which we are still yet to create. And the function is going to call user registration. So let's just get into it. Going to create a variable called DB equals new DB handler. I hope we have required that Yes, we have. We're just gonna create an instance of it. And ah, we're gonna make the result from it equals D B and call the function user registration. And that function is actually going to take the user name, the email, the past word, first name, and ah, last name. So we're going to check the status code from that response. So if rest status equals constants, http status success. Ah, we're going to return response with status press status and ah, we're just going to return it with Ah, Jason, address response. Ah, we're gonna create the user registration function in a bit. So you guys, we're going to see how it works. So the next thing is, if else, if rest status equals Constance http. Status conflict, rez, message, MSG mess. Age equals. So we're gonna have a cool function in the DB handler as well. Which is gonna, um, check if a user already has that email dress and it's going to return an Asian C B status off be status conflict. So we're just gonna write something like someone has already registered with email, address or user name and TERT, and we're going to return her response with status rehs status and, uh, with Jason dress message else, which is Ah, whatever a case that maybe we're just going to return response with status press status and ah, with Jason rest. So ah, we're done with the the user registration in index dot tv. And now we are going to start creating the function in DB Hander, which is most important part the part that it's ah, that is going on connect to the DB and actually in start the information in the DB. So, um, firstly, we're going to create a function to check if the email exists, so ah, the function will be a private function. Function is email exists, and it's gonna check if the email and the user name combination or or the user name exists . So, um, we're gonna create the statement S C M T equals this con. No prepared. It's using Ah, my SQL I prepared statements. So the statement SQL statement will be select the query. Other would be select i d from users where e mail equals, um, question mark or user name equals question marks. So what we're doing is basically selecting an i d. From, ah, the database Where that the email east the same as the email the user is trying to register with or the user name is the same as the user named the new users trying to register with. So if that query returns more than zero results, it means that that email or user name already exists. So, um, we're going to bind the parameters. S t m t equals Ah Ecmc bind, Haram and ah, we're gonna ah, where gonna specify the You have data type off the viable zor passing in, which is S s string string. They're both strings. So the 1st 1 will be email, and then the 2nd 1 will be user name. So it maps the position off the email to the first variable. The first question mark and it match. It maps the value off the second question off the user names the second question mark. So Ah, we're going to execute the statement s t m t execute, and we're going to store it. The results CMT store results and we're going to get the number off rose. So numb rows equals s TMT, num rose and ah, we're just gonna close the statement STM t close and we're going to return the num on the score rose greater than zero. So if it is greater than zero, it's going to return. Ah, true is going to return that yes, the email or the user name already exists, So ah, that's it for the function. The next function is to create that public to create that public function called user registration. So it's going to be a public function is just go ahead and copy the Cole soaking easy to create the declaration for the function public function user registration and entered the parameters. The parameters. So we are going to first hash a password so the password is going to be encrypted. We're going to use the PHP default password encryption for that. So we're going to create a pass word hash equals password. Underscore hash past in the past word and ah, password default. Asked the way of encryption as a method of encryption. So first things first after that is to, um, check if the, um, user name or email already exists. And to do that, we already created a function. So we're going to do is if no or if, Ah, this is email exists the email on ah, passing the past word as well. So if that exists, it's going to, um, create a variable cold response and said status as Constance. I hope we Okay, we required Constance. Constance, http. Underscores status, conflict, and ah, else means that, um, we are trying to Okay, so actually less Let's test what we already have. Let's test the email in the Let's say it's test at tests dot com and let's try to entered the same email. Okay, so we get an error. Let's check what that error is. Okay, I guess the reason for the error is because we didn't return the response. We need to return the response. This part of the function user registration. So, uh, that isn't the problem. Okay, so, uh, let me try to figure out what the problem. So, guys, after some time of checking on what happened Ah, letter figured out that the problem was coming from prepared, so it's meant to be prepare, not prepared. And also we need to change one last detail. So ah, the detail we need to change is in our index dot PHP. We need to remove this. We do not need this. It's kind of redundant. So Ah, let's test that out. And, ah, let's see if it's working right now. Great. So Ah, someone already registered with that e mail. We just test at test dot com so we can't use that anymore. And let's continue building our function or registration function. So ah, the next thing we're going to do is to create the query that the Curie, or however, that saved the query that inserts into the database. So query equals, insert ensue users slower in certain into users and all we're going to enter the fields, and the first field is ah, user name. Second filled is ah e mail. Third filled password Ah, for filled first name last filled. Oh, we forgot the bio, and we'll have to change that as well. And index dot PHP won't have to add the bio in the registration so Ah, First name, last name, underscore name. And the last one is the bio. So close that bracket and the values. So the values. Ah, we're just gonna enter question marks for them. Question Mark two three for five, 66 So we're gonna close the bracket on that one as well. Ah, and our queries complete. So the next thing we're going to do is to prepare the query into a statement. So STM t will be equal to you. This using our conexion con prepare Cleary. Ah, So we're going to bind the parameters that we're gonna use. So esti mt Bind, Haram, it's going to be there all strings, actually, So it's going to be six s is S S S S S s six s is and not the 1st 1 will be the user name. 2nd 1 email Third will be the password hash and ah, the fourth will be the last name I know it's gonna be the first name. The fifth is going to be the last name on the sixth is going to be the bio. So, yes, we have all that worked out. Okay, so, uh, we're gonna get the results. Using result equals as TMT execute and we're gonna get the user I d equals my SQL I It's just a function My SQL I insert on the score i d is in the connection this calm and ah, the next thing we're going to do is to close the oh, query. It's a close. A statement close the SQL request. So at CMT close and the actually want to return the result as, ah as a, um, Jason off the new user. So we are gonna do this if result. Uh, one minute. Okay, so, um, we're going to do if result we're gonna create rez variable associative array with the i d equals user on the score. I d ah, the Sirkin one be rest, actually less. Just duplicate that six times. 123456 So, um, the 2nd 1 will be user name, which will be the user name. 3rd 1 will be the past, and actually, we do not need to pass back the password, so Ah, well, leave that out and entered the email E mail. Ah, first name and ah, last name, last name and bio bile. Okay. And will make the response. Modify the response. Variable and set response equals rest. And ah, will set the response status equals Constance. Http, underscore status on the score. Success. And if that doesn't work, which is the else will. Just copy this. If results is false, change the response to results. And, ah, we'll change the status to request accepted. Okay, So, uh, yeah, that's our complete registration function. Actually, this should work as it's right now, so Ah, let's go over to our postman and ah, let's see, It's a tool at test stock calm. And ah, the user name is test one. So let's enter that. Yeah, so we have a user created. Let's go ahead and check our users table. Yep. We have a user successfully created using the email that we entered and the password using the password hash that we created. So the password is securely encrypted in PHP and ah, that's it for this video. We're done with all our, um with our registration function will be moving on to the log and function in the next video. We're almost done with the course. The idea off the course wasn't to create a full eight PHP AP I was to show you how to create your own pH. B a p I. So if you have, ah, knowledge off PHP previously, that will be extremely useful for you to create full, you know, back ends for your abs and even Web APS. So, um yeah, that's it for this video. Thank you for watching until the end. I really appreciate you guys were buying the course. I'll see in the next video. Have a great day. Thank you. 20. Login function: Hello, guys. Welcome to another video in the PHP AP Development Course. It's Abdul here. And ah, this is of the last section off the course. We'll show you how to create Ah, bonus function. Hold the lug in function. So it's going to be a pretty simple log in function. We're just going to be checking the, um, user name and the email, the user name and the password. So ah, let's create. Actually, let's copy over our post requests for the new user. And let's make that okay and let's make that log in So we only need to ah, parameters for this. So right off the bat were going to just delete first name, last name in value and ah, delete email as well. So it's going to be only checking for password and, uh, user name. So here also, we're going to delete the email password, last name and bio, and we're going to remove this block that verifies the funeral dress because we do not need it for dysfunction. Ah, we're going to be creating a new database instance to be handler instance. No, we're going to be calling a function called user log in and that function is going to require up. But we're going to pass in your name and password as the only two arguments and ah, so this can come as, um, a status and http status of success. Even though something goes wrong. According to Hall, we're going to implement the function. So what we're going to do is we're going to check if the status is not, you know, issues to be status on authorized in the first place. So on authorized, it's going to pass out all that so else. If it is on authorized, let's just make it okay, that's missing a bracket that's delete this part and ah removed. If over here, so else, if it is, ah, authorized, it's going to be rest, message, mess, age and the, um actually, we do not need all this just a l statement. So the message is going to be that the credentials supplied or invalid though credentials you supplied or not phealy Okay, so, uh, yeah, that's pretty much it for the function in ah, next up, PHP. So for the functioning TV handler, let's just copy this and ah, we'll go ahead and open up our db Handler, Let's open up db handler and just create on new function, public function and just paste what we cup it over and the the first things Ah, we're going to do to be able to actually check if this person is Ah, if this person is, you know, a user in the app. So the first thing is we can use our already created function called if email exists. But I know you're asking right now that we do not have an email. So Hari gonna check. So the slick things that I do here is just call. The function is email exists and ah, call it on. No. Ah string Cardinal as the email string with the value of no as the email and then passed the user name. Use your name, ask the user name, and then we're gonna create our query and prepare it. So, uh, query equals select. Uh, let's just select Ah, I d ah. Password. Um what else are e gonna do? Um So where, um Okay, we're going to select the I d password. Um, hello, guys. Were more well here and select the email in the last section of lower small. Show you how to create a palace function. Hold first name, last log in function. Actually, let's May. So it's going to be pretty simple organ function. We're just going to be checking the, um, user name and the were the user name and the first name so less create. Actually, that's can buy for our So we're gonna select rooms are and let's make that okay. And let's make log in users. So we only need where ah, parameters is equals. So right off the bat were going just delete Western last name bio and we're gonna prepare that query so it's going So it's going to be has word and create variable cold s u S. O. You hear. Also, we're going to delete this yumilka passed by over repair, and we're going to remove those block that verifies the funeral dress hands. We do not anti only dysfunction by going to be creating a database instance to be handler, instance notes we're going to function s which is a very long lord, the user name and that function is to require up. But we're going to pass in as an empty house work as the arguments and ah in ah s c So this can come as Imed a status on http Status of success, CMT house, finding the rhyming and also buying results going to implement. So bonds result. So what we're going to do, we're going to check the email status is not passed, you know are actually to be status off the road else wells the first so and the last. Oh, no. Authorized So going to pass out all that affect shows else if it is on authorized, let's just make it. And then we're gonna close the statement Singh s TMT racket close to delete this. So we're gonna be using a function that we haven't so else. If it is before we get right, let's just handle don't else rest the message function else. Message zones. Actually, we do not needles status and l statement equals. So the message is going to be that the credentials supplied or instance, a CCP so that is essentials on authorized you supply and we'll just turn no e responding. So let's test that we have That's pretty much word for the function. So, uh, in next up ph disable shows fillers, the function used long. Just copy this, and ah, we'll go ahead and open up. Are deeply hand have a problem with our slim Let's open up TV and pollution. I'm gonna do a bug that and get back. OK, so, guys, the problem we're having, it's actually our code actually works. It works right now. Capital is just that we haven't castings. You know, a response on this, of course, is true. So we haven't passed a response, and it's reading it as in all, so we'll just go ahead and quickly do that. It's if a results, so if they result returned true, bursting is it can use are already created function. Mom on your score rolls. I know you're asking, right, Richard, that haven't email. So Hari gonna check zero. The slick things that I do here is just ah, let's hold the function his email exists And the bullet a string quoting ally as the email string with the volatiles. I ask you your meal, i d. And then unless just you didn't copy everything because you're here, ask the user name all Yep, And then we're gonna create will or query. And that share either saying, Oh, Ah. Yep. Cleary and, um select. Let's just sadly I d We're not going to do this. We don't have ah result variable. Ah, past. And we're just going to remove this as well. I'm sorry, guys. I'm you know, what else are we? Let's do this instead in this, um, sorry. In this if state we're going to use a function we haven't yet created Gonna select password their fund. Um, the user passwords select. Let's check or DVD and ah, we password. Select the email. We're going to select the, uh Oh, there's Eser. First name, last name, actually, let's make email come before in as we're Let's change this to user password. So the there different the password coming from that blunder password passed to us for so ah, let's last creating dysfunction right now. So we're gonna select all that fee over from users and ah, actually, over here. Sorry, guys. I go to messed up again. The password verify is a PHP function already provided to us. So are we do not need to do anything that we've gotten that so it's correctly already. So if the password is the same CNT, let's equal responds this connection that is prepare queer equals constants and s CMT corn science. A CCP underscores Daddy's in the score. Sub bind, Parham says s above that. Let's just really user name, return response. User name response equals as the arrests and so else if the password was wrong, Ridge is gonna change. Ah has turned status off unauthorized. So let's say that And on, Let's log in and see so smt husband parameter and also mine results. So that's years old. The user i d. But we haven't error here. The two has word. So let's log in a game. The first name in the last game. So financials you supplied or about it last TNT such And then we're gonna close the statement as TMT close. Let's see what's going on. We're gonna be using a function that we haven't your yes word. Before we get into that, let's just handle the NL's part off this function else I'll get back to you and what's wrong that recall. So, guys, I later found out that the reason we're getting that error equals is because we forgot two at the bio or there. So this yield worthy as is Now let's check car index and status. Ah, authorize asleep there. And some Canada will just return the and let's send the request test. And yes, have are where objects return of all the values. So this is the end of the video, and we have come to the end of the course. So this is the last video and congratulations. You've created your first pH pan p I using Google Compute Engine And yeah, that's it for this video. Thank you for buying the first. Thank you for watching till the day. So, guys problem. We have a great directly. Our code actually works. It works right now is just that we haven't yet passed, You know, a response in this block of code and this block of code is true. So we haven't passed a response, and it's reading it as no. So we'll just go ahead and quickly do that. It's if results. So if the result returned true if number underscore Rose Rachel, then zero Uh, let's just make the what we Let's see. Rez. I d equals user I d. Unless your school hadn't copy everything from here. Oh, yeah. So that should be the same as that. Yep. And, um Mm. Actually, we're not going to do this. We don't have ah result variable. And we're just going to remove this as well. I'm sorry, guys. I'm messed it up. Uh, let's do this instead in this Sorry. In this if statement, we're going to use a new function we haven't yet created. It's called password. Verify the user password and ah, password. Oh, where is easier case? And let's change this to user password. So the there different the password coming from the DB and the password passed to us. So let's create this function right now. Let's copy over and Ah, actually Oh, sorry, guys. I go to messed up again. The password for verify is a PHP function already provided to us, So we do not need to do anything. We We've gotten that correctly already. So if the password is the same, let's responds. Which that is equals. Constance constants. A CCP underscore status in the score. So excess above that. Let's just read return response Response equals risks. Yes. So else if the password was wrong, bridge is going to change the return of status off unauthorized. So let's say that. And on. Let's log in and see. Okay, so that's weird. But we haven't error here. It's two columns, so let's log in again. Okay? Credentials you supplied or invalid? Let me see. Let's see what's going on. User password. No, I'll get back to you and what's wrong? Let me quickly the buck. So, guys, I later found out that the reason we're getting that error is because we forgot two at the bio over there, so Ah, the shield work as it's now. Let's check car index and confirm. Ah, yes. Just delete that and do some clean up and let's send the request. And, yes, we have our accuser object returned with all the values. So, um, this is the end of the video, and we have come to the end of the course. So this is the last video and congratulations. You've created your first PHP a p I using Google Compute engine and, um yeah, that's it for this video. Thank you for buying the course. Thank you for watching till the end. I really appreciate you and have a great day