WEBVTT 00:00:07.080 --> 00:00:12.900 In this video we're going to start writing code to reform my Escurial operations. 00:00:13.080 --> 00:00:21.790 So first of all we're going to go to FY FCP and create a new folder in the root directory of our website 00:00:21.890 --> 00:00:22.070 . 00:00:22.240 --> 00:00:27.490 OK let's call it my a school. 00:00:28.650 --> 00:00:35.850 And this creates a file inside and it's one doats introduction. 00:00:36.810 --> 00:00:38.850 Those BHB. 00:00:40.530 --> 00:00:41.020 OK. 00:00:41.250 --> 00:00:52.080 So I'm going to use the contents of the last file in PSP or the PSP top10 to populates the introduction 00:00:52.080 --> 00:00:52.920 file. 00:00:52.920 --> 00:00:55.560 So first let's create a new folder 00:01:00.600 --> 00:01:04.280 inside our course for the On-Call it's seven doors. 00:01:04.320 --> 00:01:07.620 My Escudo. 00:01:10.820 --> 00:01:11.960 OK. 00:01:12.030 --> 00:01:14.490 And let's open this folder using rockets 00:01:14.500 --> 00:01:20.410 . 00:01:26.080 --> 00:01:28.140 OK. 00:01:30.330 --> 00:01:37.640 Now let's open an introduction file. 00:01:39.740 --> 00:01:40.660 OK. 00:01:41.170 --> 00:01:45.080 And let's paste the contents of the sessions file. 00:01:45.300 --> 00:01:49.840 So this change the title to introduction 00:01:52.710 --> 00:01:56.260 and MS gets rid of the PSP code 00:02:06.720 --> 00:02:09.620 as well. 00:02:09.670 --> 00:02:15.860 And a need to connect to database. 00:02:16.470 --> 00:02:23.340 So using a bootstrap template here which uses local folders and local files. 00:02:23.340 --> 00:02:26.870 So let's get these files from the bootstrap chapter. 00:02:28.040 --> 00:02:33.290 Yes as phones and yes. 00:02:37.090 --> 00:02:38.160 OK. 00:02:39.060 --> 00:02:39.510 Now 00:02:43.170 --> 00:02:44.310 let's open our page 00:02:49.470 --> 00:02:54.890 . 00:02:57.360 --> 00:03:00.130 Here is the introduction file. 00:03:01.620 --> 00:03:02.240 OK. 00:03:02.530 --> 00:03:02.790 OK. 00:03:02.820 --> 00:03:07.870 We left some code in there to make sure we did this although it's 00:03:12.750 --> 00:03:19.150 great it's save fresh. 00:03:22.020 --> 00:03:22.220 OK 00:03:22.420 --> 00:03:35.150 . 00:03:43.200 --> 00:03:51.060 Now we're going to write some PSB code to connect our database and we're going to need to use the my 00:03:51.100 --> 00:03:53.110 Escorial extension. 00:03:53.700 --> 00:03:57.920 So my AS WELL I sense for my Esquivel improved. 00:03:58.160 --> 00:03:58.680 OK. 00:03:58.740 --> 00:04:06.270 So it is a relational database driver which you're going to use with BHB to build an interface to our 00:04:06.270 --> 00:04:08.330 database. 00:04:08.550 --> 00:04:12.040 OK so first of all let's just get introduced to this as well. 00:04:12.060 --> 00:04:16.850 I am going to type my S-curve a summary in Google. 00:04:17.470 --> 00:04:20.300 And if you go to the first Web sites KMP is Peter. 00:04:20.340 --> 00:04:23.070 That's OK. 00:04:23.100 --> 00:04:28.620 So it was here a summary of all the functions and methods we can use with my as well. 00:04:29.010 --> 00:04:38.850 In PSP 5 so we've got a couple of ways to use my girl II because the object oriented way that you can 00:04:38.850 --> 00:04:44.380 see here all the properties corresponding to that and of course the procedural way. 00:04:44.580 --> 00:04:46.760 OK and you can see all the functions for this. 00:04:46.950 --> 00:04:54.160 The procedural way is similar is very close to the old way the old my escrow. 00:04:54.240 --> 00:05:01.330 OK so so we're going to do going to connect to our database. 00:05:01.380 --> 00:05:06.820 So first we're going to use the procedural way and then explain how the object oriented way works. 00:05:06.980 --> 00:05:07.330 OK. 00:05:07.470 --> 00:05:14.740 So you can see here the functions and also you can see the description of each function. 00:05:14.820 --> 00:05:15.010 OK. 00:05:15.030 --> 00:05:16.960 So let's go ahead and create our connection 00:05:19.710 --> 00:05:27.790 so to connect to the database we're going to use a p p function called my Escurial I underscore connects 00:05:27.990 --> 00:05:31.570 OK and we're going to store the results of that function in a variable. 00:05:31.710 --> 00:05:33.700 But we're going to call Linq. 00:05:34.740 --> 00:05:48.720 OK so the function my escrow my underscore connects is going to return an objects. 00:05:48.750 --> 00:05:52.430 So if I can control cajas explore details about this function. 00:05:52.620 --> 00:05:54.800 So it's going to open a new connection too. 00:05:54.820 --> 00:05:55.830 I might as well. 00:05:55.900 --> 00:05:58.770 Server is going to return and objects. 00:05:58.770 --> 00:06:03.340 So this object is going to present the connection to the server. 00:06:03.520 --> 00:06:06.380 Ok so 00:06:09.650 --> 00:06:11.480 you use a comma there. 00:06:11.910 --> 00:06:16.530 So the syntax of this function is going to be as follows. 00:06:16.540 --> 00:06:21.040 So you're going to have the function as well. 00:06:21.150 --> 00:06:25.750 And it's called connect and it's going to take a few parameters. 00:06:25.800 --> 00:06:28.360 So for now we trying to connect to a database. 00:06:28.390 --> 00:06:31.420 OK we'll see later on how it connects to iOS 7. 00:06:31.440 --> 00:06:38.820 So to connect our database we're going to use for promises of four arguments so the first one is going 00:06:38.820 --> 00:06:47.080 to be the host of our database that we're going to have the user name they're going to have the password 00:06:47.860 --> 00:06:50.440 and they're going to have the database. 00:06:51.530 --> 00:06:52.000 OK. 00:06:52.110 --> 00:06:58.350 So we're going to need to use all these four provinces if we were connecting the server only then we 00:06:58.350 --> 00:06:59.590 would need the database. 00:06:59.700 --> 00:07:01.140 But we'd see that later. 00:07:01.470 --> 00:07:08.760 So let's put all our arguments there it looks like we successfully connected to the database and the 00:07:08.760 --> 00:07:11.500 variable this time is an object. 00:07:11.810 --> 00:07:12.230 OK. 00:07:12.450 --> 00:07:21.270 So if the connection is successful the my escrow like next function is going to return an object. 00:07:21.330 --> 00:07:26.790 Otherwise if it fails then it's going to return a boolean false. 00:07:26.790 --> 00:07:34.540 Ok so now let's check our connection. 00:07:35.530 --> 00:07:39.190 There is a common that check connection. 00:07:40.370 --> 00:07:40.770 OK. 00:07:40.810 --> 00:07:41.730 And we are just going to 00:07:45.390 --> 00:07:49.580 check if the connection is successful then print something on the screen. 00:07:49.590 --> 00:07:51.750 Otherwise brings an error message. 00:07:51.750 --> 00:07:53.180 OK. 00:07:55.080 --> 00:08:03.900 So the function we are going to be using this time is going to be my Escurial I connect error OK which 00:08:03.900 --> 00:08:09.880 is just going to return a string describing the last K'NEX error. 00:08:10.300 --> 00:08:24.390 OK so we get the rights if followed by a condition so the condition is going to be my reply and the 00:08:24.390 --> 00:08:30.280 score connects and the score error. 00:08:30.560 --> 00:08:38.930 Ok so if there is any error then this is going to be a string. 00:08:39.050 --> 00:08:41.310 OK. 00:08:41.370 --> 00:08:42.150 Otherwise 00:08:45.690 --> 00:08:50.790 he's going to be an empty value so. 00:08:51.420 --> 00:08:58.460 OK so if we have an error then we're going to bring something else. 00:08:58.750 --> 00:09:00.470 You're going to bring in something else. 00:09:00.690 --> 00:09:01.690 OK. 00:09:02.200 --> 00:09:02.810 So 00:09:06.210 --> 00:09:09.640 so if you have an error we're just going to use the function by. 00:09:10.220 --> 00:09:10.750 OK. 00:09:10.980 --> 00:09:12.150 And we are going to 00:09:16.860 --> 00:09:23.880 preens the following string strings so he's going to write error. 00:09:24.390 --> 00:09:28.330 Unable to connect. 00:09:29.580 --> 00:09:35.760 We're going to have going on and then we're going to raise the the string is this. 00:09:36.030 --> 00:09:39.940 So the string is going to be this k 00:09:43.230 --> 00:09:45.890 ok else which is going on right starts. 00:09:46.650 --> 00:09:50.400 We connected successfully to the database rather than using else 00:09:54.810 --> 00:09:59.280 we are sure that if we fulfill this condition if we have an error. 00:09:59.910 --> 00:10:05.700 Since we're using the function by the it's just going to print this on the screen and exit the code 00:10:06.250 --> 00:10:07.960 actually the whole PSAP scrapes. 00:10:08.160 --> 00:10:10.710 So we don't need that else. 00:10:11.760 --> 00:10:16.780 Keyword there so we're your rights are Vargrave right. 00:10:17.220 --> 00:10:25.620 So if we get here anyway that means thus we haven't executed this function OK which means that we don't 00:10:25.620 --> 00:10:26.980 have any error. 00:10:27.210 --> 00:10:28.950 So it's going to echo a paragraph 00:10:31.770 --> 00:10:34.020 saying connected successfully 00:10:39.120 --> 00:10:44.390 to the database. 00:10:44.550 --> 00:10:45.850 OK. 00:10:47.090 --> 00:10:53.040 All right let's try this for you refresh. 00:10:54.270 --> 00:10:57.000 OK you can see our success message there. 00:10:57.000 --> 00:10:58.130 Connected successfully. 00:10:58.290 --> 00:11:02.820 If we change anything there and we try again 00:11:27.810 --> 00:11:35.700 KSTU this because Steve will come to see what happens. 00:11:36.600 --> 00:11:36.910 OK. 00:11:36.930 --> 00:11:41.730 Now he can see our error message there. 00:11:42.900 --> 00:11:48.330 OK so the link variable is a boolean false. 00:11:49.020 --> 00:11:52.720 And also you can see the outputs of the die function there. 00:11:53.290 --> 00:11:55.970 OK. 00:11:57.300 --> 00:12:02.940 If we try with correct details then this time 00:12:07.200 --> 00:12:11.290 you can see again connected successfully to database. 00:12:12.210 --> 00:12:14.900 We can make our code look a little bit better. 00:12:14.910 --> 00:12:27.780 So rather than doing this check after attempting the connection we can destroy and say link equals this 00:12:28.330 --> 00:12:30.760 or die. 00:12:30.780 --> 00:12:31.350 This