 Hello, this is Christian. In this video, I want to show you how you can work in PHP and how you connect to a local database system in a remote database system. Okay, so here is PHPStorm, my local project over here. I'm going to show you over here the remote host. This is my FTP, by the way. Okay, I'm connected to my remote server account on Prometheus. And up here is my database. So this database here is, I showed you here two connections. One is to the local host, which is on my local database system, and this is the remote one here. So on each of these databases, systems you have have exactly the same copy of the database here. Okay, so here I'm going to show you has five tables, and here as well it shows has five tables. If you double click on the local one here admin, it has this content on it, and the same one above in the cloud as well. Okay, so when you work locally, and if you want to transfer your files to the remote one, the things you want to make sure is that you have a same copy of your database system. And I'm just showing you here what it looks like. Okay, so that's the remote and that's the local here. Now when you make connections to these databases, there are a couple of ways to do that. So before I go any further, I want to go and just explain some concepts really quick first. So here we have the local computer, and you have a remote computer or remote server. And each of them has its own copy of the MySQL database system. And then in the local machine the IP address is always going to be 127.0.0.1 probably too many zeros. And then the domain will be just local host. Okay, so this is also the host for MySQL. On the remote side it will be something similar except we have an IP address that will be unique to that domain. So we usually use the domain name. It might be different based on how it's set up, but usually it's the same domain name. And then it also has a local host too if you are running files locally on the server. Okay, so that's the setup. So here's the scenario number one. If I run my PHP file locally, everything is local only in my computer. I do not rely on the internet. So I'm silently into the system. Then this is how you usually set up. And you have PHP file, you have a host which is always going to be local host. The user is usually root. If you're just working on your own, of course it could be anything how you set up. But let's assume it's root and the password for the root is usually I put this no password, but you can change it again. And then the DB is called demo DB. So I'm connecting locally to the local machine here. And so when I run this on the browser, the URL is going to be local host and then usually you have a port number and then the file name here. So that's scenario number one. The next scenario is exactly same what you have here. But now you are running on the remote server. So everything is exactly same. Notice the host is also local host, but this only works if you're running on this machine remotely from here. So on your browser, when you run this file, you would have to go to the host which is the domain name and then the file name to run that. So you can work locally once you upload your files to the remote server. It's exactly the same. The things you might change are your username and the password. If you change your database name that too. But the connection here is the host and the username, they have to be the ones that are created inside this remote server here. So that's the remote version of it. Now the next scenario is you have a local PHP file. You run locally. Notice this is local host one, two, three index PHP. You run locally, but you are using the database on the remote server. So the host is the domain.com over here and the user in DB has to be the information that is stored inside this database. I'm running my files locally, but when I do the database connection I'm going to go over the cloud, my old internet, to the remote server and request the data back in here. And in this case, in our case, we have to use VPN because that's how our gateway is set up. So that's that. And then that's how it works. You can run locally, but then the DB is on the remote. The next scenario is kind of similar. You run on the remote server. The URL is the domain name as just like above. But the connection is you're using the domain name as opposed to local host. So when you run on the remote server, it's behaving the same thing. Even though it's on the same machine because you're using a host name of domain.com, what's happening behind the scene is that it has to go through the internet and it comes back to the domain to access the database. So if this server does not have internet access, and if you're trying to use this domain name route it's not going to work. So in that case you want to use the local host. So I hope this one here kind of clarifies how things are laid out in the program. So let's go back to the PHP here. And so here is my local version of it. So I have just some demo accounts here. I put here L host, L user, L password for the local only and this is the R for remote. So I have a remote host and then the user and password here. And then the database is exactly the same on both servers. So I just use the same name. If you use it differently just make sure you log and connect to the correct one. And then in my index file, this is locally by the way so I have here, I just put a little message here and I do my DB connection here. Notice I'm using, in this example I'm using the R host which is the remote but I could use the L host. Let me do the R host first. So that means I'm doing this scenario number two actually no number three I showed you here. I'm doing this one here oops, running local files but I'm connecting to the remote. So this is the one that some students are actually doing now because they can and also they want to access the remote database system so they don't have to do it locally. If that's the case then this is how it's set up. I'm connecting to a remote host and user and so forth and I do a little connection here. Do a query from the administrator database system. So this is the remote one so this is over here I'm going to get my first name and then display it down here down here in the message. So I'm going to run this on the browser and because it's local only I'm going to click this browser icon here and it should load and it tells me that I have successfully connected to that database and so on. Just to show that it is true I'm going to go and change my name to something else. So you can see that it's actually coming from the remote and not the local one. So I'm going to go here again, this is the remote one. I will click again just to show that and I can add the data live here. It's going to put here Kelly for example. So I save that now it's actually, let me just make sure that didn't let me do it. Let's see I have to do something I know that maybe this one here submit. Alright, so the changes have been made already and let me go back to the browser and see if now I'm refreshing. You see that now it changes to that because it's on the remote and you can also test by going to the remote PHP by admin and go into your account and see that it's also changed to that name. So I'm using the remote one and so that's what you need in order for this to work. Okay, it looks well of course I need to have a VPN if you have no VPN is not going to work and if I change to the local one then you just use the local one. So I change that to the L and then everything is local now. Okay, if it's local then it should be my name. Let me save that and go back to the browser and you see that I changed back to my name. So I hope this one kind of helps you understand the differences between the two. Now for the remote one it's the same way. So if you have FTP open directly within PHP Storm you can update these data files directly on PHP Storm and you will only see that the file has the Prometheus in front of it whatever server you're using in the file name. Now this file is the same as my index one. Notice I made some changes in here but my remote is different. So even though I had the same file in here when I opened this is actually only on the remote side. If you want a exact copy on either side you have to drag it down or download to this side and then if you want it on the other side again drag it and put it on the other side. Okay, so here on the remote side I'm using the remote one so I can't just go here and do that. If I do that it's not going to work okay because it's only local. So let me go back to this side and I'm going to go to the remote one and go to my account and then so here I'm using the remote as you can see it says Kelly because I'm using the remote one. Okay, so just to show you that it does work and of course I can't do local because if I do local it would still be the same. Okay, because local if you remember the local has a uses well even because I'm using a route and things like that. But I'm saying that the host could say local host for the remote one it would still be fine. Okay, so yeah let me know if you have any questions so just study this diagram really well so you understand what the difference is between these four scenarios okay and I will share this link as well so you can see this diagram. Alright, any questions please let me know.