Learn How To Perform CRUD on MySQL Database Using PDO in PHP | Godson Thomas | Skillshare

Learn How To Perform CRUD on MySQL Database Using PDO in PHP

Godson Thomas, Full Stack Web Developer

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
17 Lessons (1h 13m)
    • 1. Class Introduction

      1:38
    • 2. What is PDO?

      1:26
    • 3. The PDO Process

      0:54
    • 4. Create A Local Server

      1:29
    • 5. Create A Database

      3:12
    • 6. Connect To The Database

      6:42
    • 7. Insert Data Into A Database

      8:18
    • 8. View Data From Database

      3:50
    • 9. Delete Data From Database

      4:24
    • 10. Count Number of Rows Affected

      1:52
    • 11. Edit Data In Database

      5:22
    • 12. Search Data In The Database

      6:00
    • 13. The Final Project Markup

      4:08
    • 14. The Final Project CSS

      3:31
    • 15. The Final Project PHP

      9:54
    • 16. Live Search Using JavaScript And PDO

      9:38
    • 17. What Next?

      1:00

About This Class

In this class, you will learn how to use PDO (PHP Data Objects) in PHP to perform operations on a database securely. We will be using the MySQL database in this class. But you can use other supported databases and almost all the code will be the same.


We will be using an Object-oriented approach to write the PHP code. So, you will even learn how to create a class, instantiate it and call the methods on the object.

At last, I will develop a web page where all the knowledge you have acquired during the class will be used to create a complete CRUD web page. As a bonus lecture, I will also show you how to code the Live Search mechanism in your webpage where you can perform operations on the database without reloading the page.

For taking this class, it is would be great if you have the following prerequisites:

  • Basic knowledge of PHP programming
  • Basic knowledge of HTML and CSS

Although there are these prerequisites, I will explain each and every line of code that we are going to write. So, even if you are a complete beginner, you can join in. Just follow along and you will learn a lot.


After completing this class, you will be able to perform Insert, Delete, Update and Select operations on your database. This will help you in creating backend applications.


Some examples where you can use this knowledge are:

  • Creating a to-do application
  • Creating a blog
  • Creating a simple registration system
  • Creating contact form
  • And more…

I will you all the best. Keep learning and happy coding.

Transcripts

1. Class Introduction: Hi. Welcome to the scores on PDO. In the scores, you learn about video that is PHP data objects, how to use them. And what are the benefits off using video and some tips and tricks along the way? The basic understanding off, estimable and seizes can be beneficial for this course. Basic knowledge off programming can also help, but I'll be explaining each and every line of peace be called. So even if your programming for the first time in PHP, you can follow along, abusing my sequel as the database for our course after learning how to use video, we'll be creating this webpage where we can insert, delete, edit Ville and search data will also take a look at creating this live search. Very can perform database operations without reloading the page using a little bit off challenge slipped. I also have a project planned for the course. I told you to complete the project. You'll definitely have a better understanding off working with databases using video. After completing this course, you'll be able to perform all basic operations on database. Now it is just a matter off practicing and writing advanced sequel queries. You'll be able to create websites with law, informs registration forms, contact form source functionality to do lists, block admin area and a lot more. Come up with your creative ideas and implement the knowledge from this course into your projects. Man in his godson and on a Web developer. I have been programming for quite a long time. I hope that this course will be helpful for you, So with that, let's get started. 2. What is PDO?: So what is Video video stands for PHP data objects. It is basically a data access abstraction layer. Now take a look at this image. We have some data basis on the right, and we have our PSP Web application on the left. Now when we want to connect to the database is we do not connect to it directly, but we use PDO to connect to the database. Video has some built in methods, which we can use to connect. A data is now. Let's take a look at some of the advantages off using PDO video has better security compared to the conventional PHP way off. Working with databases, it has prepared statements which can help you supply input values in the query separately so that you can save yourselves from sequel injection. Video is object oriented, so this will help you write clean and better code for your website. Video has a unified A P I for different databases. So is this how to use the same building method to connect to different databases? Video also supports exception handling. It has a video exception class, you know, to set the exception attribute to the video object for exception toe work. Here are some of the databases that are supported by video 3. The PDO Process: in this video, we'll see about the PDO process. First, we connect to the database by creating a new PDO object. Then you prepare a statement and pass in the query as an argument. Then we execute the statement. If you wanna fetch, pull the data, then we can call the fits all method on your statement object. You can also use the French method toe loop through each row and a look. There are two types of placeholders in PDO positional placeholders, where you can insert a question mark in place of the input value and then provide the actual value in the execute method. As an area. The next one is named perimeters, where you can insert your placeholders with a Colin before it. Then you can provide the actual values in the execute method as an area. So that's basically for this video. See on the next one 4. Create A Local Server: we'll be writing our code in peace be. And since peace is a server side language, we need to have some kind of server to run our peace because we cannot do our development and testing in a live service. So we need to have some kind off a local server for our PSP called to run. So there are a lot of tools that you can use to create a local server for PSP development. One of the tools is called ZAM will be his exam pin the scores and there are other alternatives as well, like ma'am and ah, vamp server. So just go ahead and download any of these values example in this course. So just goto this download link over here, and it is available for Windows, Lennox and Mac. So go ahead and download for the oils that you are using. Now, once you have downloaded, install it on your computer, and once you open your application, you'll see something like this. So we have Apache, my sequel files alarm, Mercury Tomcat and all these things installed on our computer. So what do you have to do right now is click on start in front off a party and my sequel, and here we can see our server has started. So just click on admin in front, off a party, and you can see this Welcome screen off Samp. If you see the screen, that means that you have installed Zam correctly. That's it for this video. In the next video, we will create our database. 5. Create A Database: in the last video, I had shown you how to create a local server for your computer on in this video. We're gonna create the database for our project. But before that, let me show you how to create a project in Samp. So if you take a look at this girl over here, we can see that it stays local host, forward slash dashboard. So this is a project in our example folder. So let's go. Toe exam folder. This is where I have installed exam. So it is in my C drive inside the exam folder. So go to the fact, very how installed example. And in that you'll find a folder called Ste Docks. So going said that folder. And here you can find all the projects you have even know be having so many projects. But you'll find a folder called Dashboard That is what is displayed when we goto local host slash dashboard. So to create our new project will go ahead and create a new folder and we will name our project user details. Now we have created a new project in our example called user details. So if you go to our local host slash User details. We can see we have this project opened over here. We don't have anything inside our project. So we are seeing this page over here. So that's how you create a project. In example Now, to create a database here to go to PS with my admin So type local host forward slash PHP my admin. Sure. On the left side, you can find all the databases that you have will be creating a new database and we'll click on new ONDA. We'll give some name to our database, so just name it test DB and click on Create here against the artist DB Database has been created. Now we had to create a table to store all the data we name our table user details. You can name this anything you want and we need to have three columns in our table. So just go ahead and change this toe three and, uh, then click on Go. And for our fields, we need to have an I d with the type off integer and will go ahead and we will change this toe primary and click on and go. And we'll also change this to auto increments. This means that this idea will be unique and it will also increments. Now the next field will be called name. And we will change this to who are can and ah, the length will be 100. And the next one is email and the type is work out and 100. So just click on save and here we can see our table. We have I d name and email. So we have created our database and a table called user details inside it. 6. Connect To The Database: in this video, we're gonna write the code to connect to our database. So let's goto the project folder. So here in my see Samp Esti Docks folder have this follow called user Details and we'll create all RPS refiles over here. So let's go ahead and right. Click over here and click on open With God. You can also open V s Gold and open this project folder from there. Now, here's my project opened Envious code. So let's go ahead and create a new file and will Emmitt index dot PHP and I will create one more file called db dot PSP Were writing all the court for our database operations. Inside this file and in our index or pastry file will just type something So we just say this and in a browser will go to local host slash user details. So here is the contents from our indexed RPC file displayed over here. So let's go to RVs scored. And, uh, we'll write our code for connection inside our libido to peace. Be five. So let's open our db dot psv file. First of all, let's stone on RPS remote and will create a class called db so that we can in Stan shit it in other places. So to create a class in peace be type class and then the name of the class. So we'll name our class DB and instead of class, we have properties and methods so will create some properties will die. Private DB host equals local host. So here we're sitting this variable toe private because we're not gonna access this variable from outside this class. And since we're using, local host will just type local host over here as the DB host and we'll create another variable so private db user So my user is route. I think that's the default with Samp and I will create one more variable and will Emmitt db password and type the possible over here. But now, in my case, the password is blank, so leave it blank and we'll create one more variable db name. This is the name off our database. So if you go to our peace, be my admin Sure, we can see we have the name off a database test db So we'll type test debate over here and you create one more variable to store our connections with time, Private cone. Now we'll create a constructor. Constructor is basically a function that gets called when the classes instance hated. So we'll time public function and to create a constructor. Yet to dive, underscore, underscore, construct. So you have to type this exactly like this. You have to have two underscores and then type construct and make sure to spell it correctly. So what will you type over here will be executed when the classes instance hated. So let's test it by just echoing some something over here. So type class. Understand? She hated. And in our index start psb file. We just removed this from here, and, uh, we'll go into PSP mode and will require this libido PSV file. So for that year, type require once and type the name off our file review dot PSP now here will instantly it our class. So we'll create an object with a name off DB, and we said it equal to new D B. So let's save this and a let's stick our website. So if I refresh this page, we can see that glass is instance hated. So this called over here is executive and the glasses instance, hated. Now let's write the code for connecting to a database will write or cold inside a trite gas block so that we can catch any exception that we get. Now the first thing to do is specify our dear sin. So decent is basically data source Name decent will be different for different databases. So, since we are using my sequel are decent will be my sequel. Colon host equals And then here we have toe cabinet, the name off our host. So we have space fretted over here. Db host. So let's just time this arrow DB host. Then we'll have a cynical and DB name and it'll be equal toe the D V name over here. So just dive this arrow db named. We have to use this before are variable name to access the valuables from our class. Now, is it the connection variable toe new video object so we'll dive. This era of corn equals new video and we need to have three perimeters, so the 1st 1 is the decent. The 2nd 1 is the DB user, this arrow Devi user and the 3rd 1 is the baby password. So this arrow db possible with this outdated bills should be connected so we'll just echo database connection successful and for our trying. We also need to have a cat so in or casual Diab video exception e You can end this variable anything you want and heavily type die db Connection failed and, uh, but also can cap need the message that we get, so get message. So that's basically it for connecting toe our database. So we just go to our website, and when you refresh your page, we should see a message. Cold databases connected successfully. So let's refresh our page and here again, See, our database has been connected. Now we can go ahead and perform different operations on our database. So that's it for this video. See in the next one. 7. Insert Data Into A Database: in this video, we're gonna insert some data into a database. So if you go to our PSP, my admin here we can see how database called test DB and we have this user details table and and we have these fields inside out table I D name and email. So let's go to our code. And, uh, first of all, let's create a form. So let's close our PSP over here First will create our basic is unified structure. So for that envious school, you can just type exclamation and press stab, and you'll get this basic estimate five boilerplate. So for the title, real time user details and in the body he will create a form so that form and for the action will tired insert dot PSP. This is a file that we're going to create in our project and for the method we will type boast. So there are two types of methods post and get when you type get over here. Then the details are passed through the ural and when the dye post began, sent data securely So in a form, quinto have toe input, feels absolute up input off time text, and we'll give it a placeholder off name, and we'll also give it a name. Off name. We need to have this name attribute over here when we send our data toe a database because inner peace, Because we have to access this name. So for that, we have to have this name attribute over here, and we'll have one more input with type off text, and we'll give it a placeholder. And with that email and for the name will type email. And finally, we also need to have ah button. So I've been put off type submit and with time value, and we'll type insult over here, and we'll also give it a name. Insert data. So that's it for our form. So if you go to our website and if I refresh this page, we can see our form displayed over here. Let me just assume it a little. And now we don't need this message over here. So we just go to our DVD HPC file and will remove this line off court from here. So there we have our input fields and this insert button. Now you know, David RPC file will write a function to insert our data into our database. So he will type public function, insult data, and we need to have to perimeters over here. So 1st 1 is name and the 2nd 1 is email. So first of all, it'll create a variable for are pretty SQL and Kerry, right? The query for insulting detained toe our databases. So I will type insert in tow. And here we have to have the name off a table. So let's go to our pee stream. I mean, sure, we can see the name off a table is user details. So here we will tap user details and in parentis, we will type the name off our fields and then your type values and the hero type of placeholder text for ah, name and email. So that's our query. Now we have to prepare a statement, so we'll type s t empty this arrow connection arrow prepare and they had to pass this crazy over here. So SQL Now we need to execute the query soil type Christie, Empty arrow execute and in parent is is we have toe provide the values for these placeholders were deposit inside an area so well, Time square brackets and and he will die name and hear the name that we get from here and will type comma email and the email that we get from here. Now, that's it for insulting our data. Now, just echo data inserted so that we know that the data is inserted. Now, the last thing you need to do is called dysfunction. So for that will create a new file, and we limit insert daughter PSP And here we will get the data from this form and call this insert data function from our tubular PST file. So let's open the PSP mode. First of all, you had to require our debut dot peaceful file, so type require ones de Bilde PSP. And here we will check whether the insert later button waas actually clicked. So for that world AB, if he set and you have to type dollar sign, underscore Post. And here the name that we provided over here. So insert data. So just copy this from here, and, uh, based it over here and inside the if condition will write the code. So first of all, you have to get the name and email from our form for that you have to tap dollar underscored post. And in square brackets you have toe provide the name that you specified over here. So for our name, the value is name. And for the email it is email. So share your type name. And, ah, we store this inside of variable called name and we just duplicate this and changes to email. Now we had the data we need to insert into our database, so let's. Instead, she ate our class so D B equals new D B. And we call our insert data function from our DB object insert data and will provide these two variables name and email. So when I will test our website, So let's go toe here and we'll type some random name. John Door and email will be john at gmail dot com, and we'll click on insert and here against the data insulted. Now let's take in our database for that. We have the value inserted, so you know, user details. We'll click on browse and here we can see our data. The idea is automatically generated, and we have the name John Doe and john at gmail dot com. Good inside. One more data, and I will just add one more line of court over here so that after completing this insertion off data, we will return toe index or PST file. So for the diode IAB header and here, you know, did I Location indexed, or PSP? So now, after inserting our data, we will go back to the index toward Peace refined. So let's refresh our page. So here, every time Jack Smith and for the email Jack Smith at gmail dot com, and we'll click on insert. Let's refresh our PSP, my admin. And here we can see our second data, Jack Smith and the email. So this is how we insert later into a database. 8. View Data From Database: all right. In this video, we're going to get the data from our database and displayed over here. So let's go to our code Editor and individual pastry will create a new method. So we'll dive public function and we'll name it. Get data. And first of all, we will write the query and restore it inside SQL. So for the query, we will right select star from and we had to type the table name. So if you go to my database Ciric and see the table name is user details So one type user details over here and that's it with the query. Now, we will create the statement and here we will type this arrow calm arrow, prepare and well past our Cleary. Now I will execute the statement So it's TMT Arrow execute now will store the result inside a variable So we will name it Data and hero Dive Ste Empty arrow fits all this method returns all the data and we can store it inside our data variable. You can face the data in different formats like object associative area, and so will face the later in an associative area so that PDO colon Colon. Fitch underscore ASAC. Now, the last thing to do is return the data variable. So that's it with the get data method, and I will go to our index dot PHP file and here, below the form, we will display our data. We get an associate to area from this get data method. So So we will use the for each loop, tow it, read through the data. We have already created an object and instance, hated our DB class. So here we will go back into PSP mode, and here we will dive for each First of all, we need to call the get data method, so we'll type db arrow, get data, and we'll store it inside a data variable. So for each data and we had to provide a name for our it traders will just type I over here and here will echo our name and email. So, Deb Echo now hero type I and, ah, the name off our field is name. And then we will have a dash, and then we will type I again and email. So this will display the data as John Dash john at gmail dot com. So this is how the data is gonna look. And at last we will also add a line break. We need Tokcan cabinet, this soil at a dot in between. So that's basically it with our gold. Now, let's go to our website and let's test it. So if you refresh our page, we can see if we have the two names and emails that we have stored in our database, I will insert a new name and see whether it gets displayed over here. So sure, we will type a random name jennifer at gmail dot com. And we'll click on insert. And here we can see the data is displayed over here. So this is how you get data from the database. So that's basically it for this video. See you in the next one. 9. Delete Data From Database: in this video, we'll see how to delete data from the database. So we'll go to our code editor. And, uh, what we do is we will add some headings over here, so he will tap at one, and we'll say, insert data and just copy this and based it for the delete form. So type deal it. And, um, here we have to name it as delete data. And we only need to have one input box over here, and it should be off type text, and it will be the i. D. So the name will be idea as well. Onda Human will have ah, heading and we will type data. So let's go to our page and let's refresh our page. So it is our the late form. I'll just change this text to deal it. And, uh, now, let me just change this form to tow something else because it doesn't look nice. So style. I will say body onda. We'll set the phone family toe, Roberto. Now that looks better. So now and write the code for deleting the data for insulting the later we have the action attributes said toe insert dot PHP and we created this insert daughter piece refile over here and we're all the court in there. But for delivery, ljust right the cord in this index dot PHP file. So we just get rid off the action attributes. Now, when you click on this delete button on this page will be reloaded. So we'll go up here and Kerry will add a comment, delete data, and we'll just test whether we're receiving the data on several top. If he said dollar underscore, post delete data and we'll echo the idea over here. So go dollar underscore post. I'd be So let's go to our webpage and reload or peas. We just type something over here and we'll see whether it works. So here we can see our data has been passed toe the PSP code. Now just remove this echo from here and will create an idea variable and store the idea inside it. And I will goto our db dot psv file and will create a new method for deleting the data. So he real time public function delete data and well received the idea as the perimeter. Now, instead of typing it again, we'll just copy this from here and we'll baste it over here and will change the query and we'll type delete from user details where I d equals and we'll have a placeholder. Then you prepare the statement and then we execute. So instead, off name, we will type I D and I will change toe ideal here. Onda, we don't have a second perimeter now, here you'll type I d and ah, the idea that we get And he rolled up waas deleted. So that's it with the delete method. Now we'll go back to our index dot PHP file and we call the metal over here, So we'll time db arrow delete data and will pass the i d. So let's go to our page and see whether we have everything working so will refresh your page. And we know that the idea off John Doe is one. So just type one over here and press on the lid and she because he I d one was deleted and we no longer see the date our here. So if you want to delete this item over here, we'll just go to our obviously my admin. And here we can see that the I D off Jennifer is three. So we'll type three hour here. And if I oppress on deal it, we can see Idea three was deleted and the data of Jennifer is no longer here. So this is how you delete data from your database? 10. Count Number of Rows Affected: in this video, we'll take a look at a method called Roe Count Inside video. So rockin is basically used toe get the number off Rose that were affected by the recent database operation. So let's go to our debate about peace we file. And so here, instead of going the idea that was deleted, we will echo how many rules were affected. So stereotype ISTEA empty and row count. So this will return the number off roads that were affected. We just add a sentence over here. Close there. Affected. All right, so we'll go to our page over here and refresh the page and will insert some data over here and here. We will delete this data over here, so we'll go to our database and we can see that the I d off Jack Smith is too. So we'll go here and type two over here. So if I click on delete, we can see that one rose were affected. Now, let me just insert some more data. I will just go to our debido peaceful file and will make a small change in our credit. And we will remove this wear clothes from here. Now we also need to remove this alley from here, so just deleted. So we'll go to our page and will refresh. Now when I click on this delete button, all these four details should be deleted and we'll get four rows were affected. So let's click on delete and you can see four rows are affected and the four data has been deleted. So let's go ahead and change it back to what it was. So that is basically how row count works. 11. Edit Data In Database: in this video, we'll take a look at how to edit data from the database. So I have added some data our here. So let's go to our code. And here we will create one more form. So just copy this delete form from here, and we'll baste it down here and several type head. It will have an i d. And we also need to have ah, text field for our name Diab name over here Onda for the name will give value off name for the button. We will say it did data. So this is our edit form. Now. What I will do is, uh, display the ideas as well along with the name and email so that we can easily identify the idea off each of the names. So here, little type dollar sign I I d. So if I refresh my page here, we can see the I ds. All right, So we have created our edit form now will add an action. We'll create a new file called Edit Data and we will call the edit method from that file. So will tamp edit data dot PHP create a file It did later about PSP, and this will be almost the same as inserts. Or just copy this from here and paste it over here and instead off inside data type edit data on We're getting the I. D and the name and we'll create a method called aided data and will pass the I. D and the name or as soon I will goto our debido psb file and here will create a new method and multi public function aided data and will receive two perimeters i d and the name. So let's copy these three lines of court from here, and we based it over here and will change the query toe, update our data. So died update and then the table name user details. Then we'll type set and then the name off our field that we want toe update. So Diab name equals and will give a placeholder over here name and where I d is this place . Alrighty. So here we will set the values off this place holders. So here, real time name and will set this variable over here. All right, so this now should ah edit our data. So let's go to our website and refresh your page. So let's try and edit this name from here, Tony, and we will change it so stark and the i. D is 10 and also have to change this value to update. So let's go to our index dot PSP and we'll change this to and it right so will refresh our page. And we will change this. Peter does something else, so I'll type it and we will change. Peter Toe, John and, uh, click on edit. We don't see any edit over here. Let's go to our code and see what error we have made. So in our form, everything looks all right. We have the edit data, not PSP, in the action, and the names are also given correctly. So let's take our 80 data about PSB file. And here we require, or David or PSP. This is also fine, but here we can see that for the I. D. V. House said the variable as name. So let's change this tool I d and the store name and, uh, in our debido PSP. Everything seems all right. So let's go ahead and the refresh your page and let's try it again. So this time around We will change the value off Tony. So top ideal, Sten and we'll change toe Stark Andrea, click on edit. And here we can see the name has changed to start. So we will let change Peter. So type eight over here and, uh, the gender still, Parker and we can see the name has changed. So in this way, you can edit data from the database. So that's it for this video. See you in the next one. 12. Search Data In The Database: in this video, we'll see how to search in our database. So I have added some more names and emails over here in our database. So let's go to our coordinator. And here we will create a search form. So just, uh, a copy. This one from here and double pasted over here will change this to search. And, um, which changes to sort and this name to such. We don't need this name over here. We just be taking whether we have any value in our search input box. And one thing we'll do different over here is that will change this metal to get so our search done will be displayed in the Ural. Our here. Now we'll go to our db dot psb file and we'll create the search method over here. So he will type public function, search data and we'll receive a perimeter. And here we'll copy these three lines off court and we'll baste it over here. I will write our query for search, So we'll diab select star from user details. And then you have time there the field that we want a search. And here, if you type equals name, then what happens is that the visitor has to search for the exact term. If you take a look at our webpage begins the that we have this name over here. And if you want to search this were type exactly this whole name and then only this name will be shown. But we don't want that. We want that even if a little portion off this name is first we want to display this whole name and we want to display all the other names which has the term in it. So for that you have tow use a keyboard called like so like over here and here we prepare the query and will change this to name and we can have text before and after our names. So here we have the type person sign then will contaminate it with our name variable and then a percent sign or here So now, in research for a name, all the names that contain and this stone will be returned. So let's store our result inside a data available to adapt istea and the fit all and will fit as an associative memory and we will turn our data variable Now let's go ahead and call this method. So we'll do that in our index dot PHP file itself. So if you have evil type such data, So here we will type If he said And since we're using the get method, we have stabbed get over here, and we have named it search. So if we have the search value, then we create a data variable, and we'll call our search data method and will pass our system over here. So we just copied this from here and based it over here. And if you don't have the value off such, then broke it a data variable and will call our get data method. No, I will go down over here and, uh, delete this line off court from here. Here we are getting the data, so we don't want that. We can get the waiter from here. So let's go to our page and refresh it here. We can see all the data. So now let's search for something. So just that power over here and we're not changed the names, so let's go ahead and, uh, change this value toe search. All right, So fresh. This again. Okay, Now we'll search for something. And if it weaken search, we can see we have the details off Parker displayed over here. And if you take a look at the euro, we can see we have a perimeter with search. And we have the value off are such knowledge search for something else. So this type d over here and click on search. You can see we get all the names with D inside it. And we also see the Ural has been updated. Now, the last ineligible is when we have searched for something. We want the data to stay here. We don't want to go blank. So let's go to our form. And here we will add a new attribute called Value, and we'll set it equal toe some peace be called Harold. I've if he set, get search. So if the value off search is set, then we will echo the value. So just copy this and based it over here. So let's go to our webpage and see whether it works so well. Refresh our page. And here against the D is displayed over here. If he is thought for something and click on search, we can see all the names with str despair and we also have this value inside our search field. So that's basically it for our search form. If you just delete everything and click on search, we can see all the values are displayed. And even if we remove this variable from here and press enter, we can see all the values over here. So that's basically for our search functionality and also show you how to implement life search where when you type something, the results will be displayed as your type so that we will do in one of the coming videos. So that's it for this video. See when the next one. 13. The Final Project Markup: Now we'll start with the final project where we will design this webpage and we'll demonstrate the crowd operations in this webpage. And we'll use the knowledge that began from the previous videos and also the code that we wrote and will Rios it in this project. So let's get started. I'll go to my Estate Docks folder, which is inside the example folder where you have installed Samp. And here we'll create a new folder on DA Limit PDO Project. You can name it anything you want, so I'll just open this project with V s code and we'll create two files indexed or PSP and style Dorsey asses. Since this is not an estimable or thesis course, I just put up the video where I ride the market. - Thanks , Thanks. 14. The Final Project CSS: Thanks. Thanks. Thanks. 15. The Final Project PHP: all right. Now that we have designed this page, let's go ahead and start writing the peace Be. But before that, let's go ahead and, um, Goto Pierce from my admin and create the database for this project will be starting a bunch off names in this database. So let's name our database names DB and click on Create Now Got to create a table in our databases so we'll name the table names and we'll have, Ah, two columns over here. Quicken Go. The 1st 1 is the I D, and we'll go ahead and make it auto increments and also a primary key so that each idea will be unique and the next field is called name. So we will change the type to work out and well said the length to 100 click on save. So here we have a table called names, and it is inside this names DB databases. So let's go to our V s code and, uh, start writing the PSP. First of all, we'll create the db dot psb file. So let's go ahead and click on this new icon and we'll say baby daughter PSP. Now we'll go to our user details project, which we have creative in this course. So let's go toe the db dot PSP fine. And the real copy this whole gold from here and we'll baste it inside our debido psb in this project. And I would just make some changes over here. So the name off our database is names DB, and we're insulting only the name so we can get rid off the email perimeter and, uh, delete the email from here and here as well. And also delete this reference for email and the name off the table is names. So just selected these user details from here and envious code. You have this option off editing multiple words simultaneously, So sell it this world and click control de to select the next instance of the world and control. They control the till we reach the last word on day, we will change this to names. We can see that the table name has changed in all the places. Now we don't need to have this data in certain message over here, So just get rid off this line and select star from names. Everything is okay for deleting dill. It from names where I d is this I d Andi will remove this line. Of course, we don't need it. And here we have the edit method, so update names, set name equals name. Their idea is idee so we don't need to make any changes in here and for the search data. Everything seems all right now, one more thing we need to do over here is that once you create this PDO object, you need to set an after built to use the PDO exception. So for that you have to type this arrow corn arrow set attributes video colon, colon, 80 tr underscore air mode and PDO Colon colon air moored underscore exception. So now the exception should work. So let's go to our index start PSB file. And first of all, we need toe require our David or PST file. So we'll type PSB and here we'll dive required once db dot PSP and we also create an object . D B equals new DB. Now, if you scroll down over here, we can see that for the insert form. We have the action said to insert dot PSP so let's go ahead and create that file insult dot PSP for the inside or PSP will just copy the court that we had written for our user details project. So I just opened this inside dot PSP fine and just copy everything from here and paste it in tow. Our insert dot PHP in this project and here we don't need to have the email. So just delete this line off court and will also deliver the email perimeter from here. Now the insertion should work. So let's go to our website and we'll refresh our peach and Cheval Insult a name and we'll go to PSG. My admin and click on Browse. And here we can see John is inserted over here. We'll just add one more name Jimmy, and we'll click on Insert Onda. Let's refresh our bitch. And here you can see we have the two names inside it over here in our database. So now let's go ahead and displayed in our table. So let's go to via scored now here. First of all, we'll call the get data method, So in time DB Arrow get later and we'll store that inside a variable. No need to show the names in our table So let's go down over here and now here before the D R starts, let's write a loop. So we will type PHP for each data as I and we'll open our curly braces over here. Now in the TD's, we need toe echo, the idea and the name. So just go back into PSP mode and echo Dollar Sign I I D. And we'll just copy this and the little this line of code and the here Well, type name. Now, after the TR ends, we will close our calibrates. So go back into Pete's remote, close the calibrates and let's see if this works. Refresh your page and here you can see we have John and Jimmy displayed over here. Now let's work with this drop down where we will display all the names and ideas. So let's goto RVs code. And inside the select, we will write for each loop for each data as item, and we will close the curly braces here. Now, here for the value we will echo the I d so type echo item I D and hero to display the I d and the name, so we'll type echo item I d and uh And then we'll have a dash and then we will echo the name Item name. Now, we'll just copy this for each loop and and well paced it down for the edit form as well. So let's take our website care. You can see we have John and Jimmy the same goals with the aid it form now will implement delish in. So we will go toe RVs code. And here we can see for the village we have the action as deliberate about PSB. So let's go ahead and create a new file. So for our daily data of peace, we will just copy the court from insert dot PHP and based it over here. Change this to delete data and the changes toe I d i. D. And we'll changes toe delete data on this to I. D. So now let's take our website will select Jimmy and try to delete it. And here you can see Jimmy has been deleted. If he believed John, we can see John has been deleted as well. Well, just insert them again. Now, the next thing we will do is implement the edit. So if you go to index dot PHP For the edit, we have to have a file called editing data about peace. Peace. So we'll go ahead and create a new file and we based our cord from inside Change this to edit data and for the daytime 1/3 we need tohave the I d and the name. So just duplicate this and here we will type I d. I will say edit data and pause the i d and the name. So let's refresh our page and test it out. So we'll change Jimmy to James. So will select Jimmy and type James over here. If I click on update here against the The name has been changed Will change John Toe Mary and ah, here again. See, the name has been changed. So we have our insert, delete and edit working in the next we do. I will show you how to implement live search over here. So that's it for this video. See you in the next one 16. Live Search Using JavaScript And PDO: In the previous video, we had implemented the insert, delete and update in our database in this. Would you ever going to implement the live search? So let's go to our code editor and in our index dot PHP file, we'll go to the search for and here against it. This is our search form, and here we will add one more attribute called Own Key Up. And we will set that equal toe pajamas script function. So we'll be using JavaScript to call our search data method so he will create a JavaScript function and we'll call it search names and for the argument with Pass the value off this element. So in time this dot value. Now let's go ahead and create a new JavaScript file. So you name it Main Door, chess and willing. Our main Dodgers file in our index dot PHP file. So down here before the body ends, we will type script SRC and we will That main don't years now will go to Maine Dodgers and will create a function called such names. And in our main dodgy s file will create a function called such names and we'll have name as the perimeter. So what we'll do, first of all is well, console about log are value that we get over here so that we can test it. So console dot log name. So let's go to our website will refresh our page. All right, so I will open our console. So right, click and click on inspect and we'll goto the console tab. And now when you type something over here, it should be displayed on our council. So let's go ahead and type something and we can see em is displayed over here. If you drive something a are why we can see every time we type something is displayed on the screen. So we are getting the value in our sorts names function. Now we're going to send this value toe search data about PST file and from there we're gonna get the value from this debido PST file. So let's go ahead and create a new file called sorts data dot PSP. Now, here in our source data that creates refiled, we will open the PSB tag and and here, first of all, will require the debate about PSB file and then we'll be getting a value off name, So we will create a name variable. And we'll be getting the value as a post metal so little time dollar underscore Post name and they will instance she ate our DB class. So we will type DB equals new DB and we'll call our source data method. If you go inside our Libyan RPC file, we can see we have this source data function. So let's go over here and type B B arrow search data and will pass the name that we get. And the last thing to do is echo Jason data so that we can use it in our Js file. So we have to type Jason in court and then we'll pass the value that we get from here. So, first of all, your store, the result in tow a data variable and will pass that over here. So now let's go ahead and called our main dodgy s Fine. So first of all, we'll remove this council dot log and here will be using the Fit a beer, which is a new feature in year six. So just type fits. And for the first perimeter, you have to type the link. So our link is this file over here. So in type search data dot PSP and for the second perimeter really toe have on object. So in object will have method as post and we'll have a body. And the industrial said new You are search parents. So using this, we can send data to our search data without PST file. So we said the perimeter off name equals and the Wilken captain eight. Our name that we get from here now in views fits. We need to use dot then because it returns, promise now here will create a function. And, uh, we'll get the result or whoever storied as arias and in here will convert it toe Jason format so that return arias don't, Jason. Now, after that, we will call a function that will create just now, So function and we'll call this result data over here and here we will call a function called Populate Table, which we are going to create in just a minute and in here will pass this data variable and then we'll catch any exception that we get so that function e And here we will consult out log the error. All right, So now you create the populate table function, so type, function, populate table and we'll get the data on what we'll be doing over here is ah, populating this data that were created in our index dot PHP file. So first of all, let's go to our index dot PHP file and and here for Tebow divan cute class. And we'll name it data table and will access this element in our Js file so he will create a variable and real time document. Don't very selector dot data table. And first of all, you said the table inner estimable toe blank. And we looked through all the data that we have in this data variable. So here will type for Let I equals zero I less than data dot length I plus plus and here will create a constant and call it tr data container and we'll say document dot create element and will create a TR element and will upend this TR data container into our tea body. So you have to type table thought upend child, and she will past this tr data container and they will create a variable for the ideas on that led new i d equals document dot create element and will create a TV element in our new I D that we had created. We will add some interest Imo and we'll add the first idea that we get from here. So we'll time data and this loop goes from zero to the data length. So type I over here because I is the traitor over here. And then we have to type the name off the field. So this will get the first idea than the second idea and so on. And then we'll upend this idea toe the tr data container. So we'll type tr data container dot upend child and we'll say new i d. And we just copied these three lines of court and based it for the name. So in place off, new idea, we will say new name and in place of I d. We will type name. So that's basically for our main dot Js file will go to our website and see whether it works. So let's refresh our page. And here we have the data and if I type m a r y, we can see way get Mary displayed over here, onder if I type j, we can see James is this lead, which means that our life surge is working. Now let's add some more data and check it So we have added all these names. Now let's start for something. So if you type John, we can see Johnson over here. If you just type J, we can see all the names with Jay inside, it s we can see all the names that contain. As so our live such is working and our insert, delete and edit is also working. Let's take them so we will delete built from here And we can see will is deleted And we will change married So something else and we can see the name has been changed So we have completed our project And I hope you have learned something new from this. So that's basically for this video See in the next one 17. What Next?: that's it for this course. We have learned how to do the crowd operations on my sickle database using video. If you want to learn more about video, you can visit this website. Just search for PDO manual on Google and you will get this link. And if you browse through this website, we can see that it has a lot of details on video. Just for an example, we will go into PDO set actually built and here we can see it has the description and here are all the attributes that you can apply to a video object. So go ahead and check this manual if you want to learn more. And I would also encourage you to complete the project that I have prepared for this class . We can find it in the class project section. I have given the requirements needed for the project in the class Project description. After you complete the project, please submit it to the class. I hope that you have enjoyed this class. You can give me your feedback by writing a review. Thanks a lot for watching canonized a