WEBVTT 00:00:07.060 --> 00:00:15.780 Code does count for example and if we save and refresh now we see an error message four line as you 00:00:15.780 --> 00:00:15.990 want. 00:00:15.990 --> 00:00:18.340 So we didn't manage to connect to the database. 00:00:18.390 --> 00:00:20.640 That's why we see this error message. 00:00:20.640 --> 00:00:26.480 And then we can see that's our link variable is a boolean false. 00:00:26.940 --> 00:00:30.030 And then you can see the output of our die function. 00:00:30.700 --> 00:00:32.610 Ok so 00:00:36.540 --> 00:00:44.380 since the function my school-I connects returns false when we don't manage to connect. 00:00:44.640 --> 00:00:50.910 We can change the structure of our code and rather than doing the check off so we sets the link variable 00:00:51.360 --> 00:01:01.840 we can attempt connection and then use the keyword all OK and then write the dice statements right after 00:01:01.880 --> 00:01:02.440 . 00:01:02.550 --> 00:01:05.050 OK so we don't need this check anymore. 00:01:05.550 --> 00:01:07.770 So let's try this. 00:01:07.800 --> 00:01:15.990 So if you're to press the page OK so we can still see the error message for the connection but now we 00:01:15.990 --> 00:01:23.940 can see the output of our die function but we don't want to see this anymore because if you don't manage 00:01:23.940 --> 00:01:28.500 to K'NEX we just want to show this message. 00:01:28.500 --> 00:01:34.550 So there is a trick we can use for that is going to be by adding up. 00:01:35.310 --> 00:01:38.110 Just before my girl I connect. 00:01:38.220 --> 00:01:39.350 OK. 00:01:40.060 --> 00:01:46.810 Now if you refresh we can see that we see only the outputs of the dight function. 00:01:47.070 --> 00:02:02.010 Ok so we can use the this symbol actually when we are setting a certain variable to an expression. 00:02:02.190 --> 00:02:03.170 OK. 00:02:03.400 --> 00:02:11.630 And it's a good trick to avoid getting the generated APHC error. 00:02:11.700 --> 00:02:18.480 So now let's try with the Carex details and see what happens when we connect to the database and we 00:02:18.480 --> 00:02:19.980 can see our success. 00:02:20.000 --> 00:02:21.090 Mr. message that. 00:02:21.300 --> 00:02:21.980 OK. 00:02:22.440 --> 00:02:31.050 All right so that's how we can connect to a database and check connection using Escurial I am using 00:02:31.050 --> 00:02:35.790 the procedural way. 00:02:36.330 --> 00:02:39.490 Now let's try the object oriented way. 00:02:39.990 --> 00:02:41.790 OK so 00:02:45.480 --> 00:02:51.710 let's comment this and writes another piece of code. 00:02:55.020 --> 00:03:03.540 So now to connect to the database we are going to set our link variable z and objects and this time 00:03:03.870 --> 00:03:06.300 we're going to use a constructor. 00:03:06.750 --> 00:03:13.640 So you can use the keyword new and then my Escurial like constructor. 00:03:13.920 --> 00:03:18.600 So the constructor is going to take exactly the same parameters we have used earlier. 00:03:18.660 --> 00:03:25.820 So the host username password and database names you can just copy those. 00:03:25.850 --> 00:03:28.660 All right. 00:03:28.800 --> 00:03:35.580 And the difference now is is going to be the link variable is going to be in objects all the time. 00:03:35.580 --> 00:03:39.220 So even if we fail to connect to the database. 00:03:39.360 --> 00:03:48.480 OK the link variable is going to be an object unlike the procedural way where the link variable could 00:03:48.480 --> 00:03:52.640 be a boolean false when we did not manage to connect. 00:03:52.890 --> 00:03:55.050 OK. 00:03:55.270 --> 00:03:58.410 All right so now let's check the connection 00:04:02.660 --> 00:04:10.170 which is other common so that connects and thus checking connection. 00:04:10.170 --> 00:04:14.850 All right so now to check the connection we can check 00:04:17.820 --> 00:04:19.120 a condition. 00:04:19.620 --> 00:04:21.580 OK. 00:04:21.590 --> 00:04:27.900 I'm going to use a property of the link objects so this property is connects 00:04:30.330 --> 00:04:32.450 underscore Erin. 00:04:33.030 --> 00:04:34.240 OK. 00:04:34.920 --> 00:04:36.020 So you want to make sure. 00:04:36.090 --> 00:04:41.640 So we're going to check if this one is greater than zero which means that you cause an error. 00:04:41.870 --> 00:04:43.450 OK. 00:04:43.560 --> 00:04:46.020 And then if that's correct. 00:04:46.500 --> 00:04:47.540 That's true. 00:04:47.580 --> 00:04:54.380 We are going to use the function die and we're just going to Auschwitz and animates it. 00:04:54.450 --> 00:04:56.910 OK. 00:04:56.940 --> 00:05:08.820 So we're going to say unable to connect and then call on and then we're going to add the error string 00:05:08.830 --> 00:05:08.860 . 00:05:08.880 --> 00:05:16.250 And this time it's going to be a property of our objects. 00:05:16.410 --> 00:05:21.330 OK. 00:05:21.330 --> 00:05:27.780 So in the procedural way we used a schoolboy connect error function and this time we are going to use 00:05:27.780 --> 00:05:31.020 the property connect error. 00:05:31.320 --> 00:05:38.180 Ok I know it's going to return a string describing the loss K'NEX era. 00:05:38.190 --> 00:05:38.780 All right. 00:05:39.120 --> 00:05:44.850 So let's use that going to this drink. 00:05:45.180 --> 00:05:53.060 So we're going to the link objects and we're accessing the property connect area. 00:05:54.200 --> 00:05:57.400 OK. 00:06:00.450 --> 00:06:03.840 And then right at the end we're going to echo our success paragraph. 00:06:04.070 --> 00:06:08.520 Okay. 00:06:09.390 --> 00:06:15.990 And if we save and refresh so you can see that we are connected successfully to the database because 00:06:16.050 --> 00:06:17.570 all details are correct. 00:06:17.790 --> 00:06:26.900 If we change anything there that if refresh fresh. 00:06:30.150 --> 00:06:33.520 Now we can see an error message. 00:06:33.550 --> 00:06:41.160 OK corresponding to line 39 where we trying to connect and then we can see the outputs of our die function 00:06:41.170 --> 00:06:41.500 . 00:06:41.850 --> 00:06:49.770 OK well clearly it changes back to those come and have our success message. 00:06:49.950 --> 00:06:50.430 OK. 00:06:50.520 --> 00:07:00.010 So in the next video we can learn how to connect to the server and create a database in the server