WEBVTT 00:00:07.370 --> 00:00:13.980 In this video we're going to learn how to add a table to a database using BHB. 00:00:13.980 --> 00:00:19.310 So first of all before we are the table we need to connect to the database so they just copy the code 00:00:19.320 --> 00:00:23.720 we have used before to connect to the database. 00:00:25.340 --> 00:00:29.720 OK. 00:00:35.850 --> 00:00:41.300 So if we're refreshed odds you can see that we are connected successfully to the database. 00:00:41.730 --> 00:00:46.940 Let's remove the variable dumping statements. 00:00:46.980 --> 00:00:51.050 We don't need this refresh. 00:00:51.680 --> 00:01:01.890 OK so now we manage to connect to the database and now we are ready to create our table inside our database 00:01:01.910 --> 00:01:03.040 . 00:01:04.210 --> 00:01:14.180 OK so now let's just eight a three before this so that we have our page structured in a nice way. 00:01:14.310 --> 00:01:18.820 So we're going to call this connect to database. 00:01:18.890 --> 00:01:19.240 OK. 00:01:19.290 --> 00:01:24.800 And then we're going to add another piece of code saying. 00:01:24.960 --> 00:01:26.200 Create table. 00:01:26.530 --> 00:01:29.400 OK. 00:01:32.280 --> 00:01:35.750 OK so if your fridge looks better. 00:01:35.940 --> 00:01:37.680 So now to create our table. 00:01:37.860 --> 00:01:40.260 First of all we're going to create a query. 00:01:40.570 --> 00:01:41.100 OK. 00:01:41.220 --> 00:01:44.720 So this query we're going to store is in a variable. 00:01:44.770 --> 00:01:46.790 Q Well okay. 00:01:46.830 --> 00:01:51.450 And then we are going to execute does query so that we can create our table. 00:01:52.050 --> 00:01:53.820 So the query is going to be 00:01:58.260 --> 00:02:00.430 create table. 00:02:01.480 --> 00:02:03.480 OK. 00:02:04.410 --> 00:02:12.650 Now we're going to choose a name for our table task. 00:02:13.890 --> 00:02:17.920 Religious college uses for example. 00:02:19.700 --> 00:02:20.860 OK. 00:02:21.990 --> 00:02:28.680 It's one thing to mention the Eskew all key words they are case insensitive but it's good practice to 00:02:28.860 --> 00:02:30.560 write them all in capital letters. 00:02:30.570 --> 00:02:31.110 OK. 00:02:31.410 --> 00:02:34.650 So create table uses. 00:02:34.920 --> 00:02:37.910 OK. 00:02:40.060 --> 00:02:55.210 And now we are going to put the names of our columns OK inside brackets like this. 00:02:57.180 --> 00:02:59.080 OK so let's start with the first column. 00:02:59.280 --> 00:03:03.050 So we want to call it id. 00:03:03.540 --> 00:03:04.730 OK. 00:03:04.860 --> 00:03:12.460 And we want to give is a type into integer so we can write that right after the name of the column. 00:03:13.530 --> 00:03:24.580 And then if you want to specify the length we can put the length inside brackets like that. 00:03:27.180 --> 00:03:30.660 And it's good for 4 characters. 00:03:30.750 --> 00:03:38.400 OK so we can add properties of this column right after. 00:03:38.430 --> 00:03:42.510 So for example if we want this 00:03:46.560 --> 00:03:51.270 field to be a required field which means it doesn't accept any. 00:03:51.290 --> 00:03:53.180 No but. 00:03:53.220 --> 00:03:58.300 So we need to specify that saying not not. 00:03:59.440 --> 00:04:00.190 Right. 00:04:00.630 --> 00:04:08.790 And also if you want to make this a field as a primary key we can write a primary key as well. 00:04:08.820 --> 00:04:18.330 So again primary key means every single record is going to be identified using this primary key. 00:04:18.330 --> 00:04:19.540 OK. 00:04:20.520 --> 00:04:24.160 And also if you're on to the auto increment property we can do right. 00:04:24.200 --> 00:04:27.350 Or to underscore increments. 00:04:27.960 --> 00:04:28.660 OK. 00:04:28.920 --> 00:04:32.960 So two separates the fields so you can use comma. 00:04:33.180 --> 00:04:35.510 Now we can move to the next column. 00:04:35.670 --> 00:04:37.590 Let's name the next column. 00:04:37.590 --> 00:04:48.060 Use a name for example and we want to give is a type char and inside brackets I can specify the number 00:04:48.720 --> 00:04:50.110 of characters. 00:04:50.340 --> 00:04:57.900 So the muxing number I'm going to go for 30 and also I want this to be a required fields. 00:04:57.910 --> 00:04:58.480 I'm going to write. 00:04:58.480 --> 00:05:00.280 Not no. 00:05:01.100 --> 00:05:01.620 OK. 00:05:01.770 --> 00:05:07.050 So every record has got to have a value inside the username. 00:05:07.050 --> 00:05:07.730 OK. 00:05:08.040 --> 00:05:08.820 That's what's not. 00:05:08.820 --> 00:05:09.840 No means. 00:05:10.120 --> 00:05:11.280 All right. 00:05:12.060 --> 00:05:13.590 And then let's have a 00:05:16.380 --> 00:05:20.510 last name for example one of 00:05:28.240 --> 00:05:38.680 it rather than using nameless Khalid's first name is their last name and it's going to be exactly the 00:05:38.680 --> 00:05:47.150 same so same properties their last name. 00:05:47.230 --> 00:05:48.380 All right. 00:05:48.450 --> 00:05:54.910 And then let's add e-mail and they want the email to be a voucher 00:06:00.520 --> 00:06:08.110 and we can sense that it says the characters Max the first name and last name probably We only need 00:06:09.790 --> 00:06:16.810 OK 20 characters. 00:06:16.810 --> 00:06:20.320 And finally let's have a password field 00:06:23.060 --> 00:06:33.640 and we're going to give is a type 1 char with a maximum number of characters 40 for example. 00:06:33.640 --> 00:06:35.930 OK. 00:06:39.770 --> 00:06:40.070 OK. 00:06:40.080 --> 00:06:42.090 Now we're going to run our query. 00:06:42.370 --> 00:06:49.780 So we're going to use the function my Kulai underscore query to run the query and it's going to take 00:06:51.060 --> 00:07:00.430 as first promiser our variable link and then the second one is going to be the query which is the Escurial 00:07:00.460 --> 00:07:01.500 variable. 00:07:02.110 --> 00:07:02.900 OK. 00:07:03.400 --> 00:07:04.480 And what do you want to do. 00:07:04.480 --> 00:07:08.360 We want to check the outputs of this function. 00:07:08.610 --> 00:07:09.480 OK. 00:07:10.390 --> 00:07:16.730 So you going to place it inside the if condition. 00:07:17.140 --> 00:07:24.490 So if that's successful he's going to tell objects that are going to echo for example 00:07:28.550 --> 00:07:35.580 table use is created successfully. 00:07:35.690 --> 00:07:38.070 OK. 00:07:39.970 --> 00:07:45.310 Otherwise else we are going to echo 00:07:51.220 --> 00:07:57.370 for example error and then we can say unable to execute 00:08:00.160 --> 00:08:01.430 and then we can write. 00:08:01.660 --> 00:08:05.950 The variable is Cuil there and then we can add the 00:08:08.920 --> 00:08:14.930 Arab Spring there using the my girl and a scale error function. 00:08:16.430 --> 00:08:17.370 OK. 00:08:17.480 --> 00:08:21.860 And this function takes as a promiser the link variable. 00:08:22.780 --> 00:08:28.880 So if we try again before we do that let's just make sure that everything is is correct. 00:08:29.290 --> 00:08:34.450 So we created our Escurial query. 00:08:34.870 --> 00:08:47.710 So our table name is uses of course the first field gave you a type for characters Max gave all the 00:08:47.710 --> 00:08:48.880 properties. 00:08:49.310 --> 00:08:49.870 Right. 00:08:50.020 --> 00:08:52.130 Then a second feel. 00:08:52.540 --> 00:09:01.690 And then last name and email and then password. 00:09:05.490 --> 00:09:05.920 OK. 00:09:06.000 --> 00:09:08.340 And then we run Guerrieri. 00:09:08.980 --> 00:09:09.710 OK fine. 00:09:10.150 --> 00:09:12.980 So let's refresh. 00:09:14.200 --> 00:09:14.490 OK. 00:09:14.500 --> 00:09:16.840 So the table has been created successfully 00:09:16.840 --> 00:09:24.490 . 00:09:24.490 --> 00:09:27.990 Now we can see the table uses there. 00:09:28.210 --> 00:09:29.150 OK. 00:09:29.560 --> 00:09:37.030 So if you click on it you can see all the fields that we have created using BHB. 00:09:37.060 --> 00:09:42.600 All right. 00:09:46.600 --> 00:09:51.730 OK so in the next video we're going to learn how to populate this table using BHB