1 00:00:00,810 --> 00:00:05,050 I've already created a SQLite database with the items from the array. 2 00:00:05,050 --> 00:00:07,400 I've also added a few more items. 3 00:00:07,400 --> 00:00:10,120 Let's walk through how to retrieve that data with PHP. 4 00:00:10,120 --> 00:00:12,500 We can then use that data on our website. 5 00:00:14,050 --> 00:00:19,590 Since version 5.1, PHP comes with a built in mechanism for connecting to a database. 6 00:00:19,590 --> 00:00:23,046 A PHP Data Object or PDO for short. 7 00:00:23,046 --> 00:00:25,424 PDO provides some great methods for 8 00:00:25,424 --> 00:00:30,590 working with all kinds of databases including SQLite and MySQL. 9 00:00:30,590 --> 00:00:32,500 We'll be working with a PDO object. 10 00:00:32,500 --> 00:00:35,800 So I want to make sure you're clear on some of the terminology and 11 00:00:35,800 --> 00:00:38,700 syntax involved in working with objects. 12 00:00:38,700 --> 00:00:41,460 An object is a complex variable type. 13 00:00:41,460 --> 00:00:45,570 It bundles together variables and functions into a single unit. 14 00:00:45,570 --> 00:00:49,600 Those variables are called properties, and those functions are called methods. 15 00:00:50,630 --> 00:00:55,281 To give you a real world example of this, see the object is a dog 16 00:00:55,281 --> 00:01:00,306 [SOUND] a dog has attributes like gender, weight, and hair color. 17 00:01:00,306 --> 00:01:04,860 It also has actions such as eat, sleep and walk. 18 00:01:06,030 --> 00:01:12,390 If a dog is the object, gender, weight and hair color are properties. 19 00:01:12,390 --> 00:01:17,265 And eating, sleeping and walking are methods. 20 00:01:17,265 --> 00:01:20,039 We're already using an object in this project, 21 00:01:20,039 --> 00:01:24,760 the third party library used to send an email from our suggestion form. 22 00:01:24,760 --> 00:01:27,846 It provides a PHPMailer object. 23 00:01:27,846 --> 00:01:32,257 PHPMailer objects have properties to store information like subject and 24 00:01:32,257 --> 00:01:33,860 a form address. 25 00:01:33,860 --> 00:01:38,310 They also have methods which do things like Add attachment, and Send. 26 00:01:39,390 --> 00:01:43,580 To access the objects, properties, and methods, we use a hyphen and 27 00:01:43,580 --> 00:01:45,030 a greater than sign. 28 00:01:45,030 --> 00:01:47,835 Two characters that together, look like a single arrow. 29 00:01:47,835 --> 00:01:52,520 [SOUND] Let's say that we have a PHPMailer object called, Mail. 30 00:01:52,520 --> 00:01:57,610 We can access the properties in that object by specifying the object name. 31 00:01:57,610 --> 00:02:02,560 Mail, the single arrow, and then the property name, like subject. 32 00:02:02,560 --> 00:02:07,250 We can call a method on that same object, by specifying the object's name, mail, 33 00:02:07,250 --> 00:02:13,760 the single arrow, and the method name, like send, followed by two parentheses. 34 00:02:13,760 --> 00:02:15,570 Methods are like functions. 35 00:02:15,570 --> 00:02:19,285 They can receive arguments inside those parentheses. 36 00:02:19,285 --> 00:02:21,630 This send method receives no arguments. 37 00:02:21,630 --> 00:02:23,750 But you still need the parentheses. 38 00:02:23,750 --> 00:02:27,810 The Add attachment method, on the other hand, does receive an argument. 39 00:02:27,810 --> 00:02:30,470 It receives a reference to the file that you want to attach. 40 00:02:31,860 --> 00:02:35,510 The next thing we need to discuss is the idea of a class. 41 00:02:35,510 --> 00:02:40,490 In PHP, a class is a type of object or an object definition. 42 00:02:40,490 --> 00:02:43,520 It's like a blueprint or a recipe for an object. 43 00:02:43,520 --> 00:02:45,700 The class defines what properties and 44 00:02:45,700 --> 00:02:50,470 methods will exist inside any objects of that class. 45 00:02:50,470 --> 00:02:54,100 Each object is said to instantiate its class. 46 00:02:54,100 --> 00:02:59,319 Which means it is an instance or a separate object made from that class. 47 00:02:59,319 --> 00:03:02,552 PHPMailer is actually a class. 48 00:03:02,552 --> 00:03:06,250 All PHPMailer objects have certain properties and 49 00:03:06,250 --> 00:03:10,292 methods because they instantiate that PHPMailer class 50 00:03:10,292 --> 00:03:14,511 which defines what those properties and methods will be. 51 00:03:14,511 --> 00:03:16,710 PDO is also a class. 52 00:03:16,710 --> 00:03:18,200 It's built into PHP. 53 00:03:18,200 --> 00:03:21,304 So we don't have to include a third party library to use it. 54 00:03:21,304 --> 00:03:25,613 We can create an object that instantiate the PDO.class. 55 00:03:25,613 --> 00:03:31,200 And that object will have the properties and methods defined by that class. 56 00:03:31,200 --> 00:03:33,880 We can then use that object to query the database. 57 00:03:35,070 --> 00:03:36,478 Does all that make sense? 58 00:03:36,478 --> 00:03:40,610 If you're still unsure, you can check the Teacher's Notes for more information. 59 00:03:40,610 --> 00:03:41,904 But don't worry too much. 60 00:03:41,904 --> 00:03:45,000 We'll be taking a closer look at the PDO class next.