1 00:00:12,190 --> 00:00:19,000 Hello and welcome to the kulang programming language course, in this case, we want to create a function 2 00:00:19,000 --> 00:00:23,890 to insert a new student in student data in person database. 3 00:00:25,270 --> 00:00:29,200 So go to the DB connection and create new fonts. 4 00:00:32,650 --> 00:00:38,890 First, define the function, then save that accept student object as parameter. 5 00:00:38,890 --> 00:00:45,400 And if the addition of a student to the database is done correctly, the idea of the last added the 6 00:00:45,400 --> 00:00:48,340 student will be returned as return time. 7 00:00:48,820 --> 00:01:01,540 So right func save and set a student as the parameter to the model that student 8 00:01:04,000 --> 00:01:08,200 and cert and 64 as return type value. 9 00:01:10,060 --> 00:01:15,250 Now, Colin Connect function for initializing minus driver name and data source name. 10 00:01:15,670 --> 00:01:21,580 This function returns a DB object from a school package, which gave us access to methods contained 11 00:01:21,580 --> 00:01:28,870 in that package to perform crowd operations, so define a value there like DB Collins equals and calling 12 00:01:28,870 --> 00:01:30,040 connect function. 13 00:01:32,770 --> 00:01:36,790 We use Ether for closing the creator DB object ether. 14 00:01:38,170 --> 00:01:48,190 Do you buy the clothes after creating a DB object, the inventory parameter that creates a prepared 15 00:01:48,280 --> 00:01:56,920 statement for later queries or executions, multiple queries or executions may be run concurrently from 16 00:01:56,920 --> 00:01:58,240 the return, the statement. 17 00:01:58,570 --> 00:02:05,350 The caller must call the statements close method when the statement is no longer needed, this function 18 00:02:05,350 --> 00:02:06,460 returned to value. 19 00:02:06,850 --> 00:02:13,600 First is Santa object from a school package that is a prepared statement and the order is error. 20 00:02:13,960 --> 00:02:25,210 So first, define two variables like save and say comma error column equals and calling pretty parameter 21 00:02:25,370 --> 00:02:35,170 to prepare and write suitable query for create a new object insert 22 00:02:37,870 --> 00:02:40,570 into the student. 23 00:02:44,760 --> 00:02:49,800 Said variable of a student I.D. name and age 24 00:02:52,350 --> 00:02:53,190 values. 25 00:02:57,750 --> 00:03:01,230 Sit question mark instead of variable values. 26 00:03:04,650 --> 00:03:08,400 We set three question mark because we have three fields 27 00:03:11,310 --> 00:03:12,630 check every status. 28 00:03:21,700 --> 00:03:29,620 Now calling execute method from a secured package and executes a prepared statement with the given arguments 29 00:03:29,620 --> 00:03:36,400 and returns a result summarizing the effect of the statement, this method returns to values first and 30 00:03:36,440 --> 00:03:39,700 object of result inner faith and the other is error object. 31 00:03:40,000 --> 00:03:49,660 So we defined two variables like resolve and row resolved comma error calling equals and calling exec 32 00:03:49,660 --> 00:03:57,100 method on the same object say dark ExAC method and set. 33 00:03:57,130 --> 00:04:04,150 A student feels as arguments instead of question marks included statements sequentially like student 34 00:04:04,420 --> 00:04:05,530 debt, IED 35 00:04:08,860 --> 00:04:11,080 and the student, the name 36 00:04:13,690 --> 00:04:15,930 and the student age. 37 00:04:20,100 --> 00:04:21,730 Check it or a status. 38 00:04:34,290 --> 00:04:42,450 Now calling last inserted I from front cured package that returns the integer generated by the database 39 00:04:42,450 --> 00:04:49,170 in response to a comment publicly, this will be form and alter increment column, then inserting a 40 00:04:49,170 --> 00:04:49,680 new rule. 41 00:04:49,950 --> 00:04:55,290 This function returns to values first and in CC for value, and the other is error. 42 00:04:55,440 --> 00:05:02,610 So we write two variables like student I.D. and the rule the student's 43 00:05:05,160 --> 00:05:16,660 I.D. Common error coloring equals resolved start last user I.D. and check notice the. 44 00:05:16,770 --> 00:05:17,160 Was 45 00:05:23,670 --> 00:05:24,900 that the rule? 46 00:05:27,550 --> 00:05:37,480 Now, sit a student ideas writer and type of save function writer student Spike Lee format the cold 47 00:05:37,480 --> 00:05:38,800 and save the project. 48 00:05:40,720 --> 00:05:47,710 Now we could define the function name safe that accept a student object as parameter and save it as 49 00:05:47,710 --> 00:05:54,640 a record into the student table in person database and returns the idea generated of the added new record 50 00:05:54,640 --> 00:05:55,780 by database. 51 00:05:56,560 --> 00:06:01,450 Now it's time to go to the main function to use this query statement. 52 00:06:01,750 --> 00:06:05,710 Go to the main function and clear the last code. 53 00:06:10,190 --> 00:06:15,920 In this case, we want to save a new student and person database, so we should use from save function 54 00:06:15,920 --> 00:06:23,750 from TBE tools that accept a student as input arguments and returns, either that person like so first 55 00:06:23,750 --> 00:06:28,060 create and a student object from a student strike and initialize it. 56 00:06:28,340 --> 00:06:41,060 Define a variable like a student column equals model dot student and initialize it I.D., for example. 57 00:06:41,120 --> 00:06:41,660 Seven. 58 00:06:44,870 --> 00:06:53,780 Name, for example, Robert and Age, for example. 59 00:06:54,590 --> 00:06:55,080 50. 60 00:06:57,950 --> 00:07:00,560 Now, you would say function from DB tools. 61 00:07:00,560 --> 00:07:05,870 Pichai's and St create the student object as are doing this to eat first. 62 00:07:05,870 --> 00:07:14,180 Define an integer variable for return value of the function last insert i. 63 00:07:14,180 --> 00:07:26,420 The column equals DB tools, dot save and post a student as arguments to it 64 00:07:29,090 --> 00:07:31,670 and display the last insert I-T. 65 00:07:35,460 --> 00:07:39,560 Last year there two I.D.. 66 00:07:45,810 --> 00:07:51,640 Reformat the court, save the project and execute the program go wrong. 67 00:07:51,810 --> 00:07:55,290 It's like a slush main that's made that glue. 68 00:07:59,120 --> 00:08:06,500 Now we can see the output, the new student is a sort quietly in student table in the person database 69 00:08:06,500 --> 00:08:09,160 and new student ideas return. 70 00:08:09,470 --> 00:08:13,820 We can go to my school database and see these changes. 71 00:08:16,190 --> 00:08:18,200 First, create a new query type. 72 00:08:20,330 --> 00:08:30,860 Go to the database use person and create a select query sending Mr. Brown. 73 00:08:32,210 --> 00:08:41,330 The student and execute the query, we could see the newest student is a stone chronically in database 74 00:08:42,650 --> 00:08:45,860 87 seven named Robert and age 50. 75 00:08:46,430 --> 00:08:46,790 OK. 76 00:08:46,940 --> 00:08:51,950 In order not to prolong the time of decision, we will finish you and we will continue the content in 77 00:08:51,950 --> 00:08:52,910 the next session. 78 00:08:53,030 --> 00:08:53,570 Goodbye.