Intro To MySQL With Node.js | John Elder | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Intro To MySQL With Node.js

teacher avatar John Elder,

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

26 Lessons (2h 6m)
    • 1. Node mysql 1 Intro

    • 2. Node mysql 2 Install Node

    • 3. Node mysql 3 Install Wamp

    • 4. Node mysql 4 Sublime and Git Bash

    • 5. Node mysql 5 Start Sublime and Bash

    • 6. Node mysql 6 NPM Install Mysql

    • 7. Node mysql 7 Create Connection

    • 8. Node mysql 8 Create Database

    • 9. Node mysql 9 Create Table

    • 10. Node mysql 10 Alter Table

    • 11. Node mysql 11 Insert Into Table

    • 12. Node mysql 12 Insert Many Into Table

    • 13. Node mysql 13 Result Messages

    • 14. Node mysql 14 Select All

    • 15. Node mysql 15 Loop Thru Selected

    • 16. Node mysql 16 Select Specific

    • 17. Node mysql 17 Select Fields

    • 18. Node mysql 18 Where Clause

    • 19. Node mysql 19 And Or

    • 20. Node mysql 20 Where Variables

    • 21. Node mysql 21 Order By

    • 22. Node mysql 22 Delete Record

    • 23. Node mysql 23 Update Records

    • 24. Node mysql 24 Limit Records

    • 25. Node mysql 25 Drop Table

    • 26. Node mysql 26 Bonus

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class


These days everything uses a database, and MySQL is one of the most popular databases out there.  FREE and Open Source, Mysql is a great database for just about all your needs.

Likewise, Node.js is one of the most popular and powerful web development platforms.  Pairing the two together is a powerful combination!

In this course you'll learn the basics of using MySQL with Node.js and Javascript. 

You'll learn how to create databases and tables, add data, sort data, create reports, pull specific data, and more.

For this courses I'll assume you already have a basic knowledge of Javascript programming and Node, but you don't need to know anything at all about databases or MySQL to take the course.

You'll learn...

  • What Is A Database

  • How To Install Node

  • How To Install Git Bash Terminal

  • How To Download MySQL

  • How To Install Wamp and PHPMyAdmin

  • How To Install the MySQL Node Module

  • How To Connect to Database in Node

  • How To Explore MySQL With PHPMyAdmin

  • How To Create A Database

  • How To Create A Table

  • How To Insert One Record Into Table

  • How To Insert Many Records Into Table

  • Understanding Data Types

  • How To Select Data From Table

  • How To Format Our Results

  • How To Use The Where Clause

  • How To Use The Like Clause and Wildcards

  • How To Use AND and OR

  • How To Updating Records

  • How To Limit and Order Results

  • How To Delete Records

  • How To Delete (Drop) A Table

  • And More!

I'll walk you through all of this and more, step by step.  If you have any question along the way, I'm here to answer them.

If you've ever wanted to understand databases or use them in your Node programs, this is the course for you.

We'll download everything you need for this course for free, you don't need any special tools!

I'll see you on the inside!

-John Elder

Meet Your Teacher

Teacher Profile Image

John Elder


John Elder is a pioneer in Internet Marketing who created one of the first Internet advertising networks back in 1997. He sold it to a publicly traded company at the height of the dot com boom and then went on to create the best-selling Submission-Spider search engine submission software that's been used by over 3 million individuals and small businesses in over 45 countries.

Today he teaches Web Development courses at the online code school he founded.  

John graduated with honors with a degree in economics from Washington University in St. Louis where he was an artsci scholar.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Node mysql 1 Intro: All right. Welcome to the course. My name is John Elder from Carnaby dot com Will be your instructor today, And this video has been just a couple of minutes, sort of talking about what you can expect from this course. Let you know how to get hold of May and talking about the tools that we're gonna need to download to get started. So this is a course in my sequel for Node. So we're gonna be learning how to use the my sequel database with no javascript, So you should be a little bit familiar with Node. If you're not, you'll probably be OK. I'm not going to spend any time sort of discussing how we're setting up note or anything like that. But the node that we're gonna be using in this course is gonna be very basic. So if you know, if you're not familiar with no, you should be OK. You don't have to be any sort of familiar with my sequel at all or even sequel database stuff at all. So we're going to go from the very beginning. Download my sequel to download Node. We're gonna download a text editor a terminal. We're gonna download a, um, some tools that go with my sequel. So you'll have everything you need in this course. Everything to download. It's free. There's nothing to buy or anything like that. So you should be able to follow along. Now I'm on a Windows computer. Hopefully you are too. If you're on Olynyk Sora Mac, you should be able to follow along All the tools we're gonna download have a Lennox or Mac equivalent that you can download, and I'll talk about that. The next couple of videos. Ah, the code that we're gonna be writing is not gonna matter whether you're on Windows, Lennox or Mac. The code is the same. So you should be able to follow along. No matter what computer you're on. It just may be a little easier to follow if you're on a Windows computer. So my name is John Elder. Like I said, I'm your structure in this course. If you have any questions along the way, absolutely feel free to contact me any time. If you're watching this, you know me. You can, you know, use the you to meet message system to send me a direct message or you can leave a comment under the videos. There's a messaging system built in there. Either way, I try and sort of answer questions as soon as I can. This is what I do full time. I'm here all day, every day, either creating new courses or answering questions or both. Usually so, you know I'm in Las Vegas, sort of West Coast Pacific time. So if you're on the other side of the world and it's the daytime there, probably asleep here. So just keep that in mind when you send a question. But generally, I try and answer all the questions as soon as possible, at least within 24 hours for sure. So absolutely feel free. Like if you don't understand something, I want you to understand it. So shoot me a message. If something's not working, if you're getting error messages, sent me the message paste the air message that you're getting right into the message and I'll take a look at it. I'll take a look at your code, you know, whatever it takes to sort of help you understand what's going on and get you over, whatever hump your at. So like I said, there are no stupid questions. I see all the questions. I've seen everything. I've been doing this for several years and, um, yeah, it's just really important that you understand what? What you're learning as you go If you don't, you know, I'm not doing a very good job myself. So definitely send those questions if if you have them along the way. So I think that's all for this video. In the next video, we're gonna jump in and start downloading all the tools we need to download several things in order to do all this in this course. So, uh, started with that in the next video? 2. Node mysql 2 Install Node: Okay, so first things first, we're gonna need notes. So if you haven't already installed note on your computer, you need to go ahead and do that right now. So I'm just gonna head over to Google and type in node. Oops. It auto corrected me straight to the website. Let's do that again, Node. And the first thing that pops up is no Js dot org's That's the website for a node. And click on that and we go straight tooth and download section right here. And it's sort of already figured out that I'm on a 64 bit computer. You probably are, too. Nobody has a 32 bit computer these days. So what we need here is one of these. And so this one says current with the latest features. So you may be tempted to download that. I suggest you download this one, though this is the long term support sort of the latest stable version. This is sort of the, um maybe stable. Maybe not. We don't need the latest greatest in orderto do what we're gonna do with this course. So most of the time you're gonna want to download this one now Right now we're on version 10.15 point three. If by the time you watch this course it's a different version, that's perfectly fine. Whatever the most recent version listed right here is that's the one that you want. So if you're on Ah, Lennox or Mac, it probably already determined that it's giving you the link to the Lennox for Mac version . Go ahead and download and saw that. So I said, I'm on a Windows computer, something to go ahead and click this and it pops right up. You can download this, save it anywhere on your computer. I'm just gonna save it on the desktop. And, uh, I have already downloaded it in the past, so it's give me a little one next to that year's Won't have that. Go and click save already exist. Like I said, I've already downloaded it. Yes, downloads again. So down here you can see where this finished downloading. There's a little link, or you can navigate to like your desktop or wherever you saved it and double click on it there. I'm just going to click on it right here and click. Run all this over. So this is set of Wizard. Were it just It takes a minute to compute space requirements. I'm not really sure why. I'm just gonna wait for a second for to do its thing. And OK, the Senate wizard will install no Js on your computer. Click next. This is just the standard license like, except in the next. And now you can install this anywhere. I'm just gonna select the default program files. Knew Js doesn't really matter and we want to make sure that this add a path, right? We want this if you're in a Windows computer added to your Windows path and that just means that we can run note anywhere on our computer, we don't have to be in a certain directory in order for it to work. So it's already done this by default, so we don't have to do anything what next? And then finally click this install. But I'm not going to do this cause I've already installed node on my computer. But you go ahead and do that. I'm just gonna get cancel and finish, and now you're gonna wanna probably restart your computer. I don't know if it prompts you to do that or not, but it's a good idea to restart your computer when you first install node. Now, you may have an older version of note on your computer and not even know it. Um, so if you get any sort of errors, go ahead and search your old programs. Go down to your Windows Start menu and I'm just gonna pull this up here, Control, hit the control panel and then uninstall program and then come down here and find Note. If there's a different version you see right here the version number. If there's an older version just right, click and uninstall and then come back and read, download and install it again. It should work fine again. Restart your computer and you should be good to go. So that's all it takes to install downloading. It's all node very easy. Nothing complicated about it all. So that's all for this video. In the next video, we'll take a look at some of the other tools we're gonna need and go from there 3. Node mysql 3 Install Wamp: OK in this video, we're gonna download my sequel on some tools that go along with it Now there's lots of different ways you can download my sequel. You go to my sequel website and download it. I think they have an execute herbal version. There's a my sequel. Workbench. You can download it Install. We're not gonna do anything like that. Instead, I'm going to download something called Lamp. And if we go to Google and just type in Wamp, we see this Wamp server. And the reason why we're gonna do this is because this will download Wamp Server. It will also download something called PHP my Ad Men, which is sort of a graphical user interface that lets us look at the databases that we create, and we don't necessarily need to do that. But it's just a nice visual way to confirm things. So if we create a new database with knowed, we want to be able to make sure that it exists. And we can do that in note, and we will. But it's also nice to pull up PHP mind man and just sort of at a glance C that is there and everything's working now in the real world, you don't need to do that if you're creating a node app with my sequel. If you're gonna push it off down to the of the Web or something, you absolutely don't need this. But just to learn this, it's a good idea. So Lamp is a Windows program. There's also a version for Len. It's called Lamp in a version for Mac called Map. So if you want the Lennox version, type in bit NAMI lamp and then the first thing listed here is this bit NAMI dot coms four slash stack forward slash lamp and then click on that and downloaded and sold out yourself . Your analytics. You're on a Mac. You go to ma'am up at Google, and it's just this ma'am dot info for slash e n. And this is a program for Mac. Do you go ahead and download that yourself? I'm on a windows like I keep saying, so I'm gonna download this Wamp so we just go the lamp server dot com forward slash and and okay, so here are some installation instructions. We don't really need to go through any of these because we're not gonna be doing most of this stuff now. The main thing lamp is like a server, right? It allows you to run PHP Apache Web server and my sequel all on a Windows computer. Now, we're not gonna be using any of that. We're just going to using the my sequel in the Petri mind men that comes with it so we can ignore most of this stuff, but it still makes it really easy to learn. So that's where we're gonna use it. So ah, we can click the sea start or the downloads Either one. So all right, here we have lamp server 64 bit, 3.17 And if that's a different version, by the time you watch this video doesn't matter. Just download whatever is listed here. The latest version is fine. Here is one for 32 bits, but your computer is probably not a 32 bit. I don't know if there are any 32 bit computers rolling around out there anymore. Chances are you don't have one, so I'm gonna go ahead and click this and we get some more stuff blah, blah, blah. We can ignore. Let's see, it's free uh, let's download directly. Click this link right here, and it comes to the source Forge page. I generally don't like downloading stuff from source forage, but this is OK And wait a few seconds and then this will pop up and we could save this anywhere. I'm just gonna save it onto my desktop click save. That's a pretty big file. 300 almost 300 megabytes. 206 megabytes. For some reason, my Internet is just crawling today. It's really windy here in Vegas, so maybe some, I don't know. Phone lines are down somewhere. Something I don't know. So go ahead and pause the video, and we'll pick this up as soon as this finishes downloading. Okay, so we finished downloading. We go ahead and click this or you can navigate to your desktop or wherever you saved it in double click it. They're just click this. Hold this over a select language. English. Okay, its over. Accept the terms and conditions. Okay, so there's some installation instructions about some things that you have to have on your computer. You likely already have them. But if you get any errors read through this and do what it says, I'm just gonna click that and we can install us anywhere. But just click the default. That's fine. Already exists cause I've already installed this in the past. Yes, uh, created program shortcut. OK, next and then install. So it's gonna take a few minutes to install going pretty slow and there's a lot of stuff to install here. So I'm gonna go ahead and pause the video again. We'll pick back up as soon as it's finished. Okay, so we get this. We're not quite done, but we got this little pop up box. It says it was like to use Internet Explorer as the browser. Now there's no real reason to use a browser it all for wham. So I'm not sure why this is doing this, So definitely click. No, you don't want to set Internet Explorer's a default for anything ever. I use chrome. If you might use fire, Fox, whatever. But I'm gonna click. No. And it's asking what text editor we're going to use now. We're gonna look at this in the next video, but again, it doesn't matter which text editor you use. You don't have to set that up in wham at all. So go ahead, click No, again. And it's almost finished here. About 30 seconds. And, uh, we should be good to go. So after this video, we're gonna download a couple more things very, very quickly. We just need a text editor to write our code. We need a command terminal to run our code, and we'll look at that in the next video. Ah, this is taking a little bit longer than 30 seconds. I think so. I'm gonna go ahead and pause again and we'll pick this back up. Assumes that's done. Okay, So here's some explanations on how this thing works. You can read it if you want. We don't really need to. You We're gonna I'm gonna show you exactly how to use this thing in the next couple of videos. So just click next and then go ahead and click finish and we should be done. So that's all for this video exit. In the next video, we'll download our text editor and our terminal very quickly, and then after that, will jump right in and start using this thing 4. Node mysql 4 Sublime and Git Bash: Okay, We've got just a couple more things to download very quickly. So any time you're doing any sort of coding, you need a text editor s. So I'm going to use this one. It's sublime. Text editor, a completely free industry standard. Most people use this, probably one of the most used text editors amongst coders. And we also need a terminal command prompt in order to run commands. Now, Windows comes with the command prompt. It comes with the power shell, and you can absolutely use those if you want. You don't have to download anything extra. Mac and Lennix come with a terminal. You'll go ahead and use that. Just got the little search function on your computer type in terminal. It'll pop right up. So I like to use something called git Bash, which is this thing right here. And the reason why is because I like to push my code up to get hub and save it with version . Control isn't get. I'm not sure we're going to do that in this course we may, but the Windows Command prompt in the power shell don't work very nicely with git and get hub and pushing code up to get hub dot com. So I like to use this get bashed terminal and it's nice for teaching courses because it's very similar to Olympics and a Mac terminal. So everyone sort of is on the same playing field, I guess. So we're gonna download these two things in this video so very quickly. Just go to Google and type and sublime text, and it's gonna be the first thing that pops up the sublime tex dot com. And this is it You could just click here to download. I'm not gonna download and install because it's really just like a one click installation you just downloaded like we did in the last video with Wamp. And when it downloads, click the little thing in the bottom of the screen and it will start to install. If there are any selections you need to pick. Just pick the defaults for everything, and it's worked just fine. In order to use it, go down to your Windows Start menu and just type in sublime and it'll pop right up. Go ahead and click it. So the next thing we need to download install is the Git Bash Terminal so I'm just gonna type get bashing a Google. And here's the website that pops up its get dash SCM dot com forward slash downloads And right now it's on version 2.21 point zero. If it's on a different version. By the time you watch this video or course that's perfectly fine, just download the latest one. So go ahead and download this and we can download this anywhere. I'm going to say that to my desktop, and it's 44 megabytes, and for some reason it usually takes a long time to download every time I've ever downloaded. It took like, half an hour. It seems to be moving sort of quickly right now, but it's still taking along. Found 44 megabytes should download instantly on high speed Internet, which I have, so I don't know. I'll just go ahead and pause the video and we'll pick this back up as soon as it finishes. Okay, so it's downloaded and go ahead and click it and run it. All right, so we have a license quick next, and you can pretty much keep all of these default. Um, I'm just gonna go ahead and click next and again it's asking which text editor you're gonna be using. Now we're actually gonna be using sublime text, and it's already selected this one. But again, just like with the last video, it doesn't matter which text editor you have. We're not gonna be using this in conjunction with a text editor, so I'm not sure exactly why they have this kind of weird. So you just ignore it. Click next and here we're gonna be using Get from the git bash. But you might as well add the UNIX stuff to your command. Prompt. It's not perfectly. It's not absolutely necessary. But it's the default soldiers. Keep it like that and open. Ssh! This is a secure certificate that'll put on your computer so you can connect to something like get hub dot com securely next. There same thing with the open SSL next, and we keep this one as default and that one is default. And that one that looks back okay, so back, back again. We'll just keep all of these as default and okay, I've already got some get bashed terminals open, so it's sort of figured that out, and it's listing them here and it's told me to close them if I want to keep going. I'm not gonna install this because I've already installed on my computer. But you go ahead and click this installation button and walk through the final step It will install on your computer and your be good to go. So I'm gonna click. Cancel is like, said, I've already already have it installed. Uh, set up? Yes. OK, so I think that's all the tools we're gonna need. Yes, that is absolutely everything. So in the next video, we'll start to fire these things up and take a look at them and start using them. 5. Node mysql 5 Start Sublime and Bash: Okay, so we've downloaded and installed a whole bunch of stuff. Now we want to sort of play around with it, see what we've got and go from there. So go ahead and head over your windows Start menu. Now, this is on my other monitor. You can't see it, click the start menu and just type in sublime. And when you do this, you click on the thing that pops up and this will pop up. This is the sublime text editor, and this is where we're gonna be writing all of our code. And that's cool. So you go to view and then click syntax and then come down here to Java. Script does. Everything we're going to be doing in this course is JavaScript. And now, uh, anything we type in here will have different colors based on JavaScript e programming language. So we could type console dot log. You see, it changes color, and we could say hello world. And we have, you know, a job script editor. So we'll save this in just a minute. Next, I want to open up to get bash Terminal. So again, go back to your windows start menu typing get Bash, and that's G I t B A s h. Right. And when you do, this should pop up. And if I type in P W d. It tells me what directory I'm in, and I'm in the default. See users. Flat planet. My computer is called Flat Planet. I don't think the world is flat. I just find it hilarious that people do. So I name my computer that whatever your computer is called, whatever user is logged in, that should be listed there. Now, the first thing we need to do is create a directory where we're gonna keep all of our node files. And you don't have to do this. You can save these anywhere. But it's a good idea to save all your sort of files that go together in the same directory . So to do that, I'm going to type an M k D I. R. And that stands for make directory. And then we're gonna put it in the C drive and let's go, node. My sequel so created directory. Now we need to move into that directory. So, uh, we can do the change directory command, and then we just happen for class, Ford slash c and then node, my sequel, The director we just created. So if I clear the screen C l e a r and then hit PWD again, we could see now we're in this node. My sequel directory. If we click or type in LS to list the stuff that's in this directory, we can see there's nothing in there because we haven't saving anything yet. So if we pull back up our sublime text and come a profile and let's save this as and just come down here and navigate to that no directory, we just created Node, my sequel and let's just save this as what? Hello dot Js Okay, so now if we come back here and typing ls again Now we see this hello dot Js file and we can go ahead and run this if we want. But before we do that, let's really quickly type in a command just to make sure that we've got note installed. So to do that, we can type in node and dash dash version, and this will tell you the version of know that you have running. If nothing comes up here, it means you haven't installed note correctly. Or maybe you did install it. But you didn't restart your computer. Or maybe you downloaded this, get bashed, tremble first and then installed note and then didn't restart the terminal or something. So if you didn't get in this, go ahead and restart your computer or go back and download note again. So it looks like Note is running on our computer and everything is good. So clear this screen here. And let's just go ahead and run that file we just created. So we just have been know, to write, to run a note file and then hello dot Js. And when we do that boom, it says hello world onto the screen, which is exactly what this bit of code does. And so it's good to go. So one last thing we could do very quickly is start to run the Wamp server. And to do that, just go to your Windows Start menu and type in Wamp v. A. M. P. And a bunch of stuff will come up. Just click on the one that says Wamp, Server 64. And when you do that down in the bottom, right hand corner, of your Windows computer down on the task bar, a little red W Will will start up, and that's Wamp server Start sort of starting, right? If you right click on it, you can see some different settings and things you can play around with. You sort of have to wait for this to fire up. It takes a minute or so to start the first time, and after a second it turns from red to Orange. And then, after a few more seconds minutes, whatever it changes from orange to green. And once it turns to green, that means that it's up, it's running and it's ready to go. So okay, so it's turned green now, and that means it's up and running. So in the next video, we will start to actually dive into. My sequel will fire it up. I'll show you how to connect with Node with a little bit of Java script, and we'll look at the peach reminded men. Sure what that is? It comes with Wamp server, so there's nothing left. We need to install their irreligious work, and, uh, that would be in the next video 6. Node mysql 6 NPM Install Mysql: Okay, so we've got the Web server. It's got my sequel. We've got sublime text. We've got to get Bashed Terminal. We have almost all of the things we need and we need a way for node to connect to the my sequel database. And to do that, we need a module, and it's the my sequel module, and it doesn't come standard with nodes. We actually have to install it. I said there is nothing left we need to install. That wasn't exactly true. We still need to install this, but we don't have to actually go anywhere and download it. Weaken, Download this straight from the command line. I think command prompt. Throw this course. I call this this thing we're looking at right here. The command prompt the command terminal, the terminal, the command line, all these things. I just mean the get bashed terminal thing here. So javascript node has something called in PN, which is the node package manager, and that allows you to download and install stuff for node different modules, different packages behind the scenes straight from your terminal. So to do that, we just type in in P m and then install and we want to install the my sequel, um, module package, whatever you want to call it. And so hit enter takes just a second to collect its thoughts or whatever. And, uh, let's see no such file directory created a locked file such file or directory. Okay, so it's looking for a package that Jason found. We haven't created one of those yet. Not a particularly important thing right now, but it's giving us a warning for those. But it went ahead anyway and added 11 packages from 15 contribute contributors and audited 13 packages and 4.416 seconds found zero vulnerabilities. So now the my sequel package thing has been installed on her system, and we Can I go ahead and use it now if for some reason you want to uninstall that, you just go in PM uninstall and then my sequel enter, we get those same warnings that there is no package that Jason file. We can fix that if we want, in just a bit, you know, description that just deals with this package that Jason file and remove one package it package audited at 19 packages and 1.1 seconds So now it's gone from our computer. So if I hit up and then up again, you could cycle through the last things the last commands you entered into the terminal. I'll just go back up and redo this NPM install my sequel. Go ahead and install it again just to make sure it's on there. And it looks like it installed in 0.8 to 6 seconds this time. Okay, so added My sequel version looks like 2.16 point. Oh, OK, so we're going to go. Go ahead and clear the screen now in order to use this thing and sort of have it work with our node programs. From now on, we need to add it to the top of our file, and we're just gonna keep using this hello dot Js file. So to do this, we just create a variable. And let's call this my sequel and set it equal to require and then pass in my sequel as the package we just downloaded and then boom. So that's That's it. That's Install is ready to go and now are known Program can connect to our my sequel database just with coats of very cool. We'll start to look at that in the next video 7. Node mysql 7 Create Connection: okay. This video, we're gonna go ahead and create a connection from our node program to our my sequel database. And I'll also open up PHP, my and men. We won't use it yet. We'll use it. We'll take a look at it in the next video, but I want to just sort of show it to you really quickly. In fact, we could do that right now. Just come down here to this little carry, you see? Have no. I've pulled my, uh, task bar over to this monitor. Don't judge me. I have 1000 programs running. I always do. It's a problem, But just click on this little carrot down here and you could see Here's the lamp server. Mine is orange. You're should probably be green. For some reason, it's still installing or running, setting up something. But if you just click on it here, you get this little a directory and we click on PHP Mayan man. And when we dio, it opens up Internet Explorer. Uh, I didn't even know that was still a browser, but you come over here to the address and just right click and click. Copy. Just gonna close this completely, and we could just open up chrome here and paste that in right click and click paste. It's just local host for slash PHP minded men. And when we do that, we get to this. PHP my and men log in page right and right out of the box. My sequel on Wamp has a user name of route, and there's no password at all. We could change this later, but just leave it blank for now and go ahead and click Go and this will open up. And now we're inside of our my sequel database. We haven't actually created a database yet, but here's all the stuff where you can do it, and we'll take a look at this more in the next video. But if you want to go to user accounts because he hears that route, it has no password. If you wanted to double click this, see at it Privileges maybe, or let's click here, or you can add a new user. Let's see any privileges, maybe change password. There we go. So if we wanted to change the password, we could do it right here. We'll take a look at that in just a second. So what we really want to do in this video is create start to create a connection between our node program and are my sequel database. So to do that, it's pretty simple. Let's go create a connection is just a comment, of course. So I'm gonna create a variable, and I'm gonna call it con just short for connection. You can call it anything you want, Really? And we're gonna set it equal to this my seat wool package module that we just downloaded right here. My sequel dot create connection and noticed the C in connection is capitalized. And then we just want to do this and this and give us space here. So now we just need to sort of define the connection. So the first thing we need to tell it is the host, and I'm just gonna leave this blank for now. But a comma separate each of these by a comma, and the host is the the physical location of the database. So if you were doing this up on the Internet, if you had a website, for instance in your database was hosted online, you would have like an I P address for that database. You would put that there. Here. We don't have that cause we're hosting it locally, so we'll just put local host. And we'll do that in just a second. Next, we need to define the user and then every user to like. So when you use a database, you're a user of the database and you have to log in as that user. Right? So user always has a password as well. And so we could just leave that like that. So, like I said, we're hosting this locally. So we're doing local host. We just leave it like that. The user we've already discovered from PHP. Mayan men is route. We can create a different user if we wanted to. We could do that through PHP. My admit if we want or use the default and we already learned that password, there's no passers will just leave this blank. So we've now created connection. Now we have to actually connect, right? So let's, uh, connect to my sequel. Yeah. Okay. So to do that, we take this con veritable that this con object that we just created and we want to connect . And now this is a function right, and that function will throw an error if there isn't error. So it's like this now inside of here. Let's go. If air there is an error, I just throw the air. Otherwise, let's just print out to the screen, counseled out log and let's say, connected to the database. And we need another semicolon there. I'm always forgetting semicolon. So if I forget a semicolon, just scream at the computer and maybe I'll hear you. Okay, so we could save this now. And let's head back over to our terminal and we just couldn't run node hello dot Js, which is the name of the file, and boom. It's connected to the database. Now you notice the command prompt hasn't returned. It's just sort of hanging here. That's because our program, um, we haven't actually pulled it to do anything else yet, so it's just kind of sitting there waiting so that break out of this, we can hit control C on our keyboard, and that's to close the node server. Now. One thing will look at real quickly. Here is here. We had no password, so let's just make up a passwords type in some gibberish and let's save this and head back over here and run this again and boom, we get this huge air. What happened? Well, it says access denied, access denied for user route at local host, using password while of law. So it's basically saying, Hey, you put in the wrong password and it's throwing this error, and the reason why it's doing that is because we put if there's an error, we just put throw error, right? So that's kind of cool. Otherwise we could take this off, and, uh so it seems to work. So that's all for this video. We've created a connection. We've connected Teoh to the database. We only sort of hadn't have nodes. Word on this, it says, is we're connecting, and if we put the wrong password and it throws an error so it seems to be connecting. But we don't know for sure if it's connecting because we've tried to do anything yet. So in the next video, we'll extra create a database and, uh, that will show us once and for all if we're actually connecting to it, cause we can't at a database to your my sequel database. If you're not connecting, so that will be That will be the ultimate test, and we'll look at that the next video. 8. Node mysql 8 Create Database: OK in this video, we need to create a database that we can sort of connect to. Now it might seem a little strange. I'm saying Create a database were in the last video we connected to our database. My sequel is the database itself. But inside of it you can have actual databases. And inside of those databases you can have different tables. So we're connecting to our my sequel database. But we need to actually create a database that we can start putting information and and, you know, taking information out and doing all the database stuff we want to dio. And that's why we're gonna look at in this video. So it's pretty straightforward to create a database. Now. You could do it a bunch of different ways. Of course, you could just go over to PHP mired men, click on databases here and then create a new database. We could just name it, but create and boom, it will pop up now. Of course we could do that. We don't really want to do that because we want to do this programmatically using node because, you know, in the real world, if you're kind of you know doing this in the plowed up on the Internet or something. You're likely not gonna connect with pH. Remind man. No, you absolutely can. It's just better to do it programmatically and you're here to learn how to do this stuff with note anyway, so we should probably do it that way. So all we need to do is come down here and beneath our council log thing here, we need to just write some code. And any time you're connecting with node to the database and doing stuff, you're creating a query. This is a database query, and that query can do anything you want. It could create a day to basically create a table. I can add information to a table. It could take information out of a table whenever you're querying the data waste. That's just sort of what we call connecting to the database and doing something. So to do that, we're just gonna use our connection that we created con dot query and then inside of here. We want to let's see and create database. And then let's just name it node. Um D b no database. Right. So this is pure sequel and sequel stands for structured query language. It's the language of databases, and every database has slightly different sequel. So we're using my sequel, right? My structured query language. If you're using Post Graze sequel using the post Crest structured query language if you're using Ah, see what a Microsoft version? I think there's a C T sequel I remember correctly after matter. In this case we're using my sequel. All sequel is pretty much the same. It's just slightly different. So if you don't know sequel, that's fine. I'm gonna walk you through all the sequel that we're gonna be doing throughout this course . But this is just, Let's just say we're just using a little bit of sequel here, So create database and then name it. Now we need to create this function, and there could be an error or there could be a result. I need to pass those in, and then if there is an error, we want to throw the air. Otherwise, let's just console that log a message and say, um, database created Boom that Okay, so I think that'll work looks right, Right? So just to recap, we created this new little thing right here. Ah, building off of our connection here dot query or creating a query or passing in a sequel Command, Create the database, and we're gonna create a database called node D B and that can either give us an error or the result if there is a result, we could print that out if we wanted to, but we're just gonna instead print out database created. Okay, So go and save this head back over to our terminal. Let's clear this screen and run the program again. And, boom, we get connected to the database and database created. Now, how do we know that this database has been created? Well, let's head back over here to our HP mired man. I just hit, reload and boom right there. No db and notice. I put it as capitalized, and it, um, actually created it as lower case. So I guess this is not case sensitive. So in the future, I might have done something like that. Cool. So now, from now on, any time we want to create any time we want to connect to that specific database, we need to modify our connection here, and we need to sort of, say, database. Which database were connecting to now we called this nude. Do you be him? But common here just because. All right, so it's now, from now on, whenever we run this, it will only connect to this database. And you say only this database. Are there others? Well, yeah, Court, sort of. This is a my sequel database that's just got installed by default. There's an information scheme home which most databases have by default, a performance scheme and assist database. We click on these has all kinds of different stuff. We don't care about any of this. All we care about from now on is this node db. And here we're now inside of our no D B database. There's nothing here. There's no tables or anything, and we can create a table right here. But again, this is not a course in peach remind men were just using this as a backup to see that what we did actually happened. We need to do this programmatically using javascript and node so we'll start to look at that, will create a table in the next video 9. Node mysql 9 Create Table: Okay, so in this video, we want to actually create a table with some columns, and we want to designate what those columns are and move on from there. So I'm gonna come up here and it's gonna save this file as let's just save it as table dot Js I want to start designating these is different files just so that later on you can go back and I'll post the source code to this up to get hub. And you can look at each of these files individually to see the code to, for instance, creative table. In fact, let me just show you real quick if we head over to get have dot com for slash Flat planet. This is my get have account. You can follow me here if you want to, or whatever, but click on repositories and then node, my sequel course. Look on that here. And then here's the Here's gonna be the source code for this course. So we click on hello. That Js You could see this is the last thing that we just created that connects to my sequel and creates a database call node date DB. Okay, so now Let's go ahead and look at how to create a table. So let's see instead of create database so we don't need to create a database Every time we run this right, we just need to do it one time. Once the database is created, we put it up a reference to it up here, and we can get rid of all of this because we don't need to create that database every time we were on this program, right? So now we need to create a table. And it's pretty simple again in the same sort of section here in our connect function, because every time we do something, we need to connect and then run our query, right? So we learned in the last video that everything is basically a query, and, uh, that's cool. So let's create a table now. First, we can do this conduct query like we did last time and then type in, You know, our sequel stuff in all of that. But this time, the sequel that we're gonna right in the last episode it was just create, um, database and then name database, right? That's just a little bit of sequel and that's not too bad. But in the future, we're gonna be doing lots of sequel. So instead of typing that all in that line, what we want to do is just create a variable. And I'm gonna call this sequel and said that equal to you know, whatever we want. And then instead of typing all that Super Bowl in here, we could just type in that variable and then, just like before, it's a function function, and it can have either an air or result and boom. And if there is an error type is very hard, throw air. Otherwise, let's just console log out. What do we want to say? Table has been created. I don't die. All right? And then that that. Okay, so this will work. Now we just need to sort of figure out what sequel we want to do to create the table. And sequel is very simple. And the last one it was, create database. Now we want to create a table. So can you guess what the sequel command is? It is create table and not that hard. Now we need to name the table. So what do we want to name this thing. Well, let's pretend we have a company and we want to log our customers. Let's create a customer table customers. And then we put this like this, and now we need to actually to find the column. So a database has columns and rows, and everything in a column is the same, and everything in a row is different. So this make more sense in just a minute when we actually look at this, but we need a column for everything we want to save. So let's say we want to save their name and their email address. That's two columns we need a column for name in a column for email. So let's call the 1st 1 name. And now we need to describe what kind of data is gonna go in this column. We need to assign a data type. If you're familiar with data types, there are a whole bunch of moment and database land. There's, ah, you know, a few ones you're always gonna use, namely, the one used the most is var car or far Char and 2 55 and of our char is just like a string . This is gonna be a string of text, a bunch of letters and numbers, and they can be up to 255 characters long. And so we're just gonna put 2 55 as the default. Okay, so then we put a comma and let's say email, right and email is also gonna be of our car with 255 whatever characters. Okay, so that will work now, any time you create a database and this is more just database knowledge here, you need to create something called a primary key. And that's just a number. So every entry in your database will be assigned automatically a number, and that so that we can look up any in true we want based on its number and these increment automatically. So the first time you enter something that's number one. The next time is Number two. The next time is Number three. So if we put Bob Smith bob bob dot com, he's number one. If we put Linda Smith linda at smith dot com, she's number two. It's a primary I D. That follows around that customer forever and is just important for all kinds of database reasons. So we need to actually create that. So I'm gonna go idea what was Just call it. I d. Because it's basically an I d and the data type for this is integer I nt and visitors are whole numbers. So 1234 not 1.51 point six whole numbers Integers. Now we want this toe auto underscore increment. Right? And we want this to be the primary key. And let's put a comma. Okay, so that should work. Let's go ahead and save this and running to make sure that it did. So we will need node away. What do we call this table dot Js people that Yes. Okay, So connected to the database table has been created. Now, are we sure it was created? Let's head back over here and, uh, reload and boom. Sure enough, there's a customer's table. If we click on it, we can see it has an I. D column, a name column and an email column. Very cool. So I'm gonna go ahead. Well, we'll do this in the next video in the next video. I want to show you how to sort of alter a table that's already been created, and I will look at that in the next video 10. Node mysql 10 Alter Table: Okay, The last video, I should you have to create a table in this video. I want to show you how to alter a table and why you might want to do that. So I'm gonna head back over to PHP my admin real quick and just click on the home screen here and then click on databases and then are no DB database. And here's that table we just created. I'm gonna go ahead and lead it. I'm going dropped to delete this. Okay, so it's gone now, going to come back to our code, And I'm just going to take out this primary key stuff, right? So let's save this and run it again. So it's a, uh, node table that Js acted. A table table has been created and come back over here and click. Reload, She sees. Sure enough, that deleted table is back again. If we click on it. There is a name column in an email column. There is no I d column, and now we go. We forgot we forgot to enter. I d. We need that primary key. It's important for all kinds of different crazy database things. So how do we fix that? Well, pretty simple. We just come back over here and let's go. Let's just get rid of all of this because we don't need it anymore. And let's go alter table. We need to alter this table. So just like before, let's create a variable sequel and well put stuff in there. Now we need to connect Critic, Query string, and we're gonna pass in that sequel. It's a function. It can have an air or a result and boom inside here if error. Uh, there we go. If air throw the air, otherwise consul dot log our table has been altered dot All right, so my colon semicolon. Okay, so now we just need to create the actual sequel to alter a table. And to do that, any guesses the first time it was created Database. The second time it was create table. Now we want to alter table. What do you think the command is gonna be? Altar or table? It's very complicated. And the table we want to alter is customers, right? Is that what we called it? Better make sure. Let's go back. Yeah, customers right there. Your customers here, Lee. So we want to alter table customers. And what we want to do is add a column and we want to call that. Call him i d. We want it to be an integer We want to auto incrementally it. And we wanted to be the primary. He basically all the things we put in the last video. But this time we forgot because oh, we forgot. All right, so let's save this head back over to our terminal and control C two close out of that, clear the screen and let's rock, uh, node table Js connected to the database. Our table has been altered, and we can confirm that by coming over here hitting reload or F five on your keyboard looking customers and inside here. Now we have name email and I d. So it has been altered has been updated, and we've done it programmatically pretty simple, pretty straightforward. So that's all for this video. In the next video, we'll show you have to start actually adding data into our new table, you know, adding stuff into those columns and we'll look at that in the next video 11. Node mysql 11 Insert Into Table: Okay, so we've got our table set up, and now it's time to actually start putting data into the table, programmatically. So come up here and let's save this as, um in served into Okay, so now you're at all this. Well, actually, let's just keep this and let's go insert into We'll go ahead and just change this or get rid of that. And then for the council law here, um, data inserted into table. Okay, you come back. So now what we need to do is insert stuff into tables. Now, this is always the sort of format that we're gonna use. We're gonna create a variable. We're gonna run that variable through our query through our connection. Just this guy up here, we're gonna either throw an error or get some sort of message back. That is very, very straightforward. Simple, Which is great, cause he likes complicated stuff, especially when it comes to databases. All we have to do is actually sort of know the sequel commands that we need to type and you're already starting to figure out. Probably the sequel commands are all very easily easy Sequels, Very easy computer language to learn. It's not really a computer language, but we can treat it like it is. So what we need to do now is insert data into our table. So the command we want is insert into Now we just name the table that we want. So its customers and then we need to say what we're inserting into. So it's name or which columns were gonna be inserting into so name and email And let's just make sure row quick. So name and email we don't need to pass an I. D. It's gonna auto increments and add that automatically. So when we don't need toe, specify that we do need to specify name and email, which we have done here in here and now we need to type in the values that will be passing . And here we just type in the stuff. So I want to enter. John Elder is the first customer. So that's my name. And then comma in my email address John E. For 196 at gmail dot com. Okay, so I think that should work. So go ahead and say this as insert into dot Js control s to save, and it's from this insert into and you notice I just typed in i n And then I hit the tab key on my keyboard and it auto corrected to the name of the file. As long as you don't have other files in that directory that also start with I, it will print it out for you, so you have to type it in every time. So that's cool. So let's go ahead and do that connected to the database. True data inserted into table. All right, so let's pull apart PHP mind men and hit Reload to see if it worked and where to go. There we go. Name. John Elder. See right here is you back and email Johnny for 196 at gmail dot com noticed that the I D has automatically been added as one, and that is very cool. So let's head back over to our code analysts type and Mary Smith and her email address is mary at smith dot com. But and save this head back over George Terminal Control. See? Close that out. Push the up arrow key to run this again. Connected a database data inserted into table. Very cool. Um, come back here and hit reload and we see another row has been created. So each of these across is a row. Each of these up and down is a column. So the name column Up and down. They're always the same names, right? Left to right. Rose early is different. This is John Elders Row. This is Mary Smith. Throw right, and the thing we really want to look at is the I. D one and two. So it's that's working correctly. It's auto incriminating on I. D. So now in the future, if we want to look up, I d number one, it'll return John Elder stuff, and we'll look at that in a little bit very, very cool and very easy. So that's how to add just one sort of record one row at a time. And you may do that one thing at a time. But a lot of times you're gonna have more than one thing toe ad at the same time, and we'll look a sort of doing more than one thing at the same time. In the next video 12. Node mysql 12 Insert Many Into Table: Okay. The last video we looked at, inserting one record into our database at a time. That's pretty simple. In this video, we want to look at inserting lots of different records all at once. So here we just need to modify this a little bit. And before we do that, let's go ahead and save this as insert, um, insert many, I guess. Okay, so we need to modify this a little bit. First, we're gonna come over to our values section here. I'm gonna get rid all of this, and we're gonna replace it with a question mark. Now, what we need to do is create an array full of all of the stuff we want to insert, right? So let's creator an array, and I'm just gonna call it values and said that equal to the square brackets. Now we can just insert into this as many values as we want. So let's just put three right, So inside here. Let's go, Tim. Um, I don't know. Let's just go. Tim and Tim's email is tim at tim dot com. Right, and you'll notice it's the same format. So we have two things here. This corresponds to these two things here, right? So the number of items here has to correspond to the number of items inside each of these individual things. So here we can go. Tina and Tina. Is it Tina? At tina dot com, You noticed each of these is separated by a comma here. And then finally, let's go, or Ah, and she is at laura at laura dot com. Okay, so now down here, in our actual query, we need to, uh, fix this up a little bit. We need to add that array and values. All right. Data inserted into table when we could keep this the same. Uh, we want to get really interesting. We can go, um, records inserted and then con Canton eight. This is the result dot Affected rose. That should work. Yeah. Okay, so let's save this and run it. So it's insert many dot Js. So node insert many That Js boom connected to the database. Records inserted. Three. Notice it. It figured out how many we've inserted, and it tells us that on the screen kind of cool. All right, so let's head back over here to our PHP minded men and hit reload And when we see in fact, Tim, Tina and Laura have all been added. Their I DS have been auto incriminated, which is very cool. Yeah, and that works so a little bit more complicated, but not too bad, really. And pre simple. So that's how to add more than one thing at once. In the next video, we'll take a look at connecting to the database and pulling data out and, you know, doing stuff with it, displaying it on the screen, whatever, and we'll look at that in the next video. 13. Node mysql 13 Result Messages: okay, before we move on and learn how to pull stuff out of the database has been just a second talking about this very last bit of code we put in the last video, this result that affected Rose. I kind of just blushed past that, and it's kind of interesting. So let's take a look at it. So let's come up here and save as it's called us results Js and I'm just gonna come up here . And instead of inserting all this stuff and just very quickly instead of this, let's just Well, let's create this sequel. Uh, our sequel equals it's just really quickly insert into customers, and we want name and email and the values the Ellie you yes, will be. What? Count Steve and Steve at steve dot com. Okay, so let's just right. No, we need a very yes. Okay, let's say this and run it real quick. Okay? So connected to the database. And now here is a list of things that we get back whenever we insert something into our database. And so you see, feel Count that zero affected Rose. That's what we looked at in the last video, right? Insert I d. That's the primary. He that was auto implemented and assigned server status to warning count zero. There were no mornings. Any messages? There weren't any messages. Protocol 41. I really don't know what that is, but it returned true and changed. Rows equals zero. So let's head over here really quickly hit. Reload. And sure enough, Steve steve dot com was done as very cool. So we can take any of these and out put them onto the field. Our own to the console, right? So affected Rose We looked at last time, so to do that, we were just in here. Result dot and then just paste that in, says Object job script. Just kind of object oriented. This is an object oriented sort of thing. Slap a period and then put the thing in there and that work. So just very quick little video to explain that in more detail it's useful, especially if you need to debug something or if you need your program to return different messages. That's a way to get those messages and ah, pretty cool. Pretty simple. So that's all for this video. In the next video, we'll pick this back up and we'll learn how to pull stuff out of the database and put that on the screen and do stuff to it. All that good stuff, that'll be the next video. 14. Node mysql 14 Select All: okay, This video, I want to start to talk about pulling data out of the database, and that's going to take several videos because this is a big sort of subject and there's lots of moving parts and lots of different ways. You could do it. So we're just gonna dive in and start doing this So don't come up here to file and let's save this as, ah select dot Js. And the reason that is is because when we pull data out of a database were selecting that data, we're picking it and pulling it out, selecting it. So to do that, we use the select statement Something come down here to our sequel statement here and get rid of all this stuff. And to do this pretty straightforward. It's just the select sequel command. And now we need to tell it what we want to select, and we'll get into specific things later on. But for right now, I just want to select everything, right? So we use the star to designate everything, so select everything from now. What table do we want to select from? Well, we only have one table. It's the customer's table. So That's fine. Now, one more thing we need to do is down here. We've been returning an error or the result, but now we can also return the fields and the fields are like the different column names and the database name itself and all Bunches, whole bunch of stuff. We'll look at that a couple of videos from now and show you exactly what all that stuff is . But for now, we'll just leave it there. Okay, So now we want to just return the result, Which is this guy, right? So we're gonna select everything and return it there. So let's save this and head over to our terminal and run this and boom. We get all of this stuff now you'll notice it looks kind of Ah. I mean, there's a lot of stuff here, and it's not very user friendly, right? It's not just printing out. John Elder and John Elders email. It's printing out all this other stuff. So what is all this stuff? Well, these curly bracket things. These are objects, just javascript objects, and you'll notice there inside of these square brackets, so a square bracket and javascript most programming languages denotes an array. So this is returning an array. And inside of the array, each item, each array item is an object, right? So if you're familiar with programming languages and a raise and a ray is numbered so each item in an array has a number and they started zero. So this is a zero with item in the array. This is the first item. Second item, third item, fourth item and fifth item in the array. So we can pull any of these things out by just calling their item number. So let's do that real quick into cola An array is not a database thing. It's just a programming thing. Use the square brackets and then just the number of the things I remember the 1st 1 is the zero a thing. 2nd 1 is the 1st 2nd 3rd and so on. So we're calling, calling the first item in this array. So let's save this and run it control. Seed it, close out our server, run it again, and boom, it returns. Just the zeroth item, which is John Elder and you could see has all of our columns, the name, the email and the i D. But It's all just throwing up on the screen. This is again not very user friendly, not very cool, so we can actually pull specific items out of here. So this is an object. We could do object oriented things to it. And to do that, we just slap a period at the end and then call the object item that we want. Name email or i d. Let's do that real quick. Let's just pull the name. So to do that, we just go dot name, right? If we wanted email, we would go dot email. Right. So let's say this. Come back here. Control seed. Close it, Run it again. Boom. John Elder, right. You can come Canton eight if you want. Right. So we could go, Um, Plus, let's get a space and then plus again. And then let's call dot email. Is that the name? Uh, email, Right? Sure. Why? It's not changing color there. Oh, save it. Run it again. Control, Seed. A break. And here we haven't John Elder, and then the email. You can get fancy if you want. We could, uh, throw hype in there just for sort of a visual. Whatever control see your Run it again. We get John Elder, a little bar in the middle, so very cool. But this only kind of works. If you know the number that you want to call and you may not, you may have hundreds of numbers. You may have thousands of not numbers items in your array. You may not know how many items, Aaron, you're a We know there are six because we can kind of glance at it and see just by sort of looking at it here. But, you know, if you're pulling from a huge database, you might have millions of these items. And so how do we print out specific wounds, or how do we loop through? Each one will look at that in the next video. 15. Node mysql 15 Loop Thru Selected: in the last video, we pulled out everything for more database. And then we added, We just printed out one item onto the scream How we print out all the items in a more user friendly manner just like this. Even if we don't know how many items Aaron are array. How many items we actually pulled out of the database. That's we're gonna look at in this video. So we're code back up real quick Now, there are lots of different ways toe loop through data in any programming language and javascript as well. I like to use for something like this. Probably a four loop. So that's what I'm gonna do right now. I'm just gonna create a real quick for loop. I'm gonna create a variable I and this is gonna be a counter. And now we can go for therefore loop. I equals zero semi colon, and then I for I less than we need to know the length of our array. How many items air in there. And we can do that by calling the dot length function. So we just go result. Excuse me dot length and this will return the number of items in our array. And if we pull this back up real quick, we can see there are 123456 items in our array. They start at zero. So this is the zeroth item, and this is the fifth item. So if we know there are six items weaken Just loop around until we hit six. When we hit six. We know there there is no sixth item. The sixth item is its number is five. Stay with me if you're not familiar with the Rays, so we can do it like that. So suppose back up. So as long as I which at the moment is zero is less than six, keep looping is what this is saying. And then every time we loop through, we want increment our counter. So our counter starts at zero. We want to print out the zero with item loop through incremental counter ones are a counter becomes one. Then we put out the first item loop through increment our counter. So our counter becomes to print out the second item loop through and on and on, known until we hit six. And then we want to stop so to increment. We need to just go. I plus plus right eso then inside a here. We put all this stuff and let's get rid of the email. We don't need do that. Let's just print out the names. Okay, So, Michael Okay, so this should loop through and print out every item in our array. So we save this and run it. Well, let's clear this screen. Oh, we forgot to change this. So instead of just putting out the zero of item each time, we want to print out the actual next item, which is I, which is our counter. So he needed change that. So save this control. See? Clear the screen. Run it again. All right. So John Elder, Mary Smith, Tim, Tina are and Steve. So that's one way to loop through and print out everything in your table or whatever. There are other ways to do this as well, which I think we'll look at it, probably in the next video. There are other loops you can use that's a four loop. You can use a while loop. There's all kinds of different loops you can use. There may be an easier loop to use But that's the first thing that came to my mind when I thought about how would I do? This is a for loop, so pretty simple. So that's pretty much how you pull stuff out of a database. Now we're selecting here. Everything. We're pulling everything. So we're pulling. The names were pulling. The emails were pulling the I. D s. You don't have to do that every time, and in fact you probably shouldn't. You know, if you have a massive database with millions of records and hundreds of columns, you don't want to pull everything out of that. Every time you query the database, you might want to just pull out the names. So how do you just pull out one specific column, for instance? We'll look at that in the next video. 16. Node mysql 16 Select Specific: again this video. We want to select just specific things. We don't pull everything from the database like we did in the last video. So head over to our code. I'm gonna save this as, um, let's say save as I was called this select underscore name. Okay, So specific data select specific data. So what we want to do is instead of, you know, just pulling everything we want to just pull. Oh, say the name. Right. So we know the column column, his name. That's what we're gonna call. And that's what we're gonna select. We're going to select it from our customers. Taito table. So the same thing here, a result in fields. Let's get rid of this just because for now, bring it back if we really want Teoh. Okay, So let's save this and head over here and run it. So that was no select name. Oh, throwing error. What do we do? I is not defined. No. All right, So instead of pulling this, let's just return. The complete results will save this. All right, Clear this and run it again. Okay, so we get just John married Tim, Tina, Laura and Steve. Right So instead of pulling the name and the email and the i d, we're just pulling the name. Now, the same exact stuff holds true here as the last video. If we wanted the loop through this stuff, we could do that again in the exact same way. So I won't go through that again because we've already looked at that. But, um, yeah, this is just a better way to pull just specific things. So here we've pulled the name code back up. Maybe you want the name and the I D. How do you do that? Well, you just select name comma. I d. All right, you receive this. Come back over here, Control seed to close it out. Run it again. Who now will return the name and the I d. All right, so you just use a comma slap in whatever other columns you want and pretty simple. So, you know, sometimes you might want to just pull everything out of your database. We use the little star. More likely, you're going to just pull out specific columns and do it this way. You can always just pull out everything and then do some sort of voodoo like we did in the very first video on select or were we kind of format out report ourselves. But you know, if you have a huge database, it's it's CPU intensive to just pull everything, especially Redoute it over the Internet. You don't want to necessarily pull everything out of your database it once you just pull out the specific thing if you want, and this is how you do it. So I think that's all for this video. In the next video, we'll take a look at what this field's thing is and see what that's all about. 17. Node mysql 17 Select Fields: Okay, so we've learned how to select specific data. Now, let's look at this. Feels field. Right. So I'm going to appear and save this as Let's save this as fields dot Js Okay, so was clean this up a bit. There we go. Okay. So, up until now we've just seen returning error and results. Now we have this other thing, this field. So what in the world is that? Well, we can very quickly come down here and just type in fields to see often time, not just with node databases in any programming language. If you're not sure what the thing is, you can just kind of print it out to the screen and look at it. That's I find the best way to do it. You can go look up the documentation if you want, but I was just print the thing to the screen and see what the heck it is going to go from there. So we're going to hear just gonna put this to the screen. So see this and let's head back over here, clear our screen, and we want nude fields dot Js and boom. We get this whole big thing and this is basically just a bunch of information you might want to use for different things. Uh, or you just might wanna see. So again, this is an array, right? And inside of here, it looks like there are two objects, this one and this one. So we have field packet and field packet. So in the first, I don't My guess we have the catalogue, which I don't know what that is. The database. This is just the name of our database. No db The name of our table customers. Interesting. The original table. I don't know what the difference between these two are. We have name, which is name. That's a column name we have, Um and then that name has a character length and type flags and decimals. Sure, exactly. Protocol 41 is true. I don't know what that is, except for I know. 41 is my lucky number. My high school basketball number. Anyway, so then we have the 2nd 1 where we have, um the I d. Oh, you know what? We've meant? A bit of a mistake here. Now, this is just returning the fields for this query or we just called name and I d. So it's returning the fields for name and I d. That's why there's only two looked a little weird, but again, the 2nd 1 is the I D one. So let's let's change this. Let's run this again. Let's just pull everything. Like everything from customers. OK, so now let's look at that would be more interesting. Close this. Clear the screen and run it again. All right. Much more data here because there are three columns. Right? So we have this item, this item and this item because we have three columns. Now there's three items, right? So we have the 1st 1 says the database name. Do they all? Yeah, they also the database name in the table. Name within the name of the field is name. The name of this field is email because that's the name of the column. In the name of this field is I d. Because that's the name of the column. So just a bunch of information you can see. Why would you ever need this? I don't know. You probably wouldn't accept if you want the name of the column. So if we're doing a report or something, and we want at the top for to name the column. We could do that. So let's say there are three items here. Let's print these things out to the screen. So just like before, we can call a specific item in our array. So let's say the zero with item, right? Let's save this and just run that clear this screen. So we get just the first item zero with item, which is name right. So let's say we wanted the name of it. We could call its object oriented, remember? So we could do object e things by calling dot name. We already looked at this a few videos ago, So if we save this and run it again, clear the screen when we just get name right. If we want to find out with the first column, is that's our email column. I think Right, so we save this, you'll see Run, run the skin boom! Now it says email. If we did the 3rd 1 it would print out I d. So you know, that's kind of useful. If you wanted to create a little report and then under each name, you know, for instance, if we wanted to, then underneath this type and counseled log and then let's just print out something like that. And then copy this underneath that we did, um, result zero with one, which I think was John Elder. Right. All right, so let's say this and see if this works just kind of doing this on the fly, you will see. Clear the screen. Bang. Boom. Oh, throw error. What did I do wrong, council? Not if I misspelled Consul. Why didn't you tell me Right there? Boom. Uh, so what happens when you do things on the fly? All right, so we get email, get this dotted line and then underneath it says John Elder. If we wanted to loop through like we did a few videos ago, we could loop through and print out underneath this all of the names. But we don't want email. We want names. All right, save this. Just playing at this point. Let's run this again. All right? So now it's his name. And in general, there, Like I said, we could look through this and they print out all the names underneath it. We'd have ourselves a little report, so That's maybe one reason why you might want to use the fields thing to get the names of the, um, columns in your database. I don't know, but it's kind of interesting, and it's something you should probably know about. So we just talked about it. So anyway, that's pretty much it for this. Now, in the next video, I want to talk about the where clause the where clause lets us pull even more specific data out of our table, and we'll take a look at that in the next video. 18. Node mysql 18 Where Clause: Okay, so we've started to learn about the select function, and that allows us to either pull everything out of the database or specific columns. But we might We might want mawr control. We might want to pull out just specific records from a column. You know, if you have millions of records, Yeah, you could print out all the names, but you might only want all the names named John. Or you might want Onley all the I DS above a 1,000,000 or something. You know, whatever. You might want specific things from those columns. So how do we do that? We use the where clause. So that's what we're gonna look at in this video. So let's pull up our code here. I'm just gonna say this as where dot Js and just to remind you, um, saving these is different file names so that you can look them up on, get hub and get the specific code. So if you're curious about where Klaus code, you can go to my get home page and look for the wear dot Js file and get the codes. That's why I've been doing that. I think I mentioned that earlier but nice to remind you. Okay, So what we need to do here is specify where, so let's say, um, select name from customers and then below that we use the wear. And let's say where I d Yeah. What? We want to do this? Yeah, where I d equals one. All right, so we know the person with I d. Number one is John Elder. So we wanted just select record, right? So let's get rid of all of this stuff, and let's just print out the result, see what we got. All right, So save this. Come over here and node where dot Js in. Boom, It's pulling. Name John Older. Now we can do all kinds of different ways with this. We can. Instead of saying select name from customers, we could go select everything from customers. We did that. It's gonna get the same thing. Um, same result, right? It's just gonna pull everything right. So that's how to pull one exact thing. But you likely don't always know the exact thing. Well, before we get into that, let's look at this a little bit deeper here. I've put where I d equals one, right. We have six records in our database. So let's say where I d is less than four. All right, so that should print out 12 and three if we've done it. Right. So let's save this and run it and see about that. Boom. So here we get I d 12 and three. If we wanted also, four we could do where I d is less than or equal to. So basically what I'm saying here is you can use all the comparison operators. You know what comparison operators are less than greater than equal to less than or equal to. Greater than or equal to etcetera. You can use all of those there now. That's okay, but it's kind of messy. So we could go where I d equals John Elder. But we need to change. I d to name. So is that. Let me look at this real quick. John and Elder are both capitalized. Okay, so let's come back here and save this. Run this Code Patrol C Oh, oh, uh, it's sloppy. We need single quotation marks, and then we need to close it with a double, cause you notice both things starts with the double quotation mark. It needs to end with a double quotation mark. You can't use double quotation marks inside of there. You got to use the single silly mistakes. Okay, Save this and let's clear the screen and run this and boom, We get this John Elder record now, this is not a great way to do it, because you know what? If I accidentally did under lower Case E will that work? Well, let's save it and run it and see troll, See, Run this again. It does work. So certain databases that will work certain other databases. It won't work if their case sensitive or not. Apparently, this works for that. Still not a great idea, because you might not necessarily know that John Elder is in there, right. Instead of just being very specific like that, how do you kind of search a little bit? Well, instead of using equal, you're out of this where name is like and then we use single quotation marks and let's say Jay, and then we need to put this wild card. That's the percentage sign, I guess. Right. So Okay, so now we're saying return all of the results Where the name is like J, right? So if we say this and run it, we get John Elder. Do we have anything else in there? I think we have Tim and Tina. Those were all with tea, right? So let's put a t where the name is like t Say this and run it. Yeah. Now we get Tim and Tina. Right? So, like, is often a better way to do it. And just be sure to use that percentage wild card thing, and you should be OK so you can use, like I said, equal to less than greater than greater than or equal to less than or equal to. You can use this like you can also use and and or I think we'll look at that. It is getting a little bit long, so we'll get that in the next video. 19. Node mysql 19 And Or: okay. Continuing on with where, um, we learned how we can use comparison operators equal to less than greater than or we can use. Like we can also string together several of these using and in Or so I'm gonna start out with. Or so we're saying select everything from customers where name is like a T or I d equals zero one ID equals one. So think about the logic of or or means or right it's either do this or that. So what we're doing here is we're searching. We're looking for all of the things that have a name that has a t at the beginning of it, right. So we get all of those things or we get the one with an i d. Of one. So there's only one record that has an idea of one. Right. So this should return three things. Tim, Tina and the i D or the I d one. So let's say this and take a look real quick. So we're still in Where? So yeah, it returns Tim, Tina and then John Elder, which is I D of one. Right? So that's what or does it does this or that. So if the 1st 1 is true, it will return its things. If the 2nd 1 is true, it will return its things right If either or are not true, it would just go to the next one. So, for instance, if we went or I d equals 95 we save this. Come back here, screen real quick and run it really gonna get to results because there is no i d of 95 right? So it just ignores it because we use or or allows a a thing to be ignored. If it's not true. On the other hand, we could use. And now this is saying return everything that has a name that starts with T and a thing with an idea of 95. If either of these aren't true, nothing gets returned because we need to do both. That's what and means it does. Is it means do this and do that right. And if you can't do both, don't do any with or if you can't do both, you just do whatever you can. That's what or means this or that and means this and that. So they both have to be true logic and always confuses me. Must be my mind. Okay, so let's control. See, Run this again. We get nothing because there is no I d of 95 right? So since this isn't true, it returns false. There is no i d 95. It doesn't print out anything. Now if we change this to one, there is one with one control c and run it again. But we also get nothing. Why? Well, because we want to return a result that starts with T and has an idea of one, right? Tim and Tina's I d is not one. So both of these things aren't true. This is not true. This is true that we had a bunch of start with t but none of those ones that start with t have an i. D. Of one. And so it won't return anything. That's the difference between and and or so I'm kind of Ah, silly distinction, but I don't know something to keep in mind. I guess so. And that's all for this video. In the next one, we will learn how to kind of break this up a little bit so that this string isn't so long and we can pass things in instead of saying like, you know, anti We can pass in a variable instead. Look at that in the next video. 20. Node mysql 20 Where Variables: Okay, so we've been looking at where and it's kind of easy to see. Especially if we start stringing these ands and ors on here. That this whole thing could get a little bit convoluted and long and hard to read. So we like to break these sorts of things up with variables. And we've seen this in the past. Heck, this whole thing right here is a variable that were passing in right here. So I'm gonna change this back to or Okay, So how do we add some variables in here? Well, pretty simple. We just create the variable appear we name it and let's say, um, we will call this far, uh, name search. I don't know, and we'll set that equal to something, and then let's go far. I d search the reason I'm calling him underscore search is because if we called it name, where was they? Wear a name like name. It gets a little confusing. So I'm I'm using an underscore. Surge just changes around around a little bit, so let's keep the same thing. Let's go. The teething here. That name and we're we want i d. We want this to be I d one. Whatever. Okay, so now we need to change this instead of this. We need to put in these placeholder things, and it's just that question mark. Right? So where the name equals the question mark or the name is like the question mark or the address the i d is equal to question Mark. Now we need to swap out the question mark for these things. Where do we do that? We do that right here, right before this function call. And we could do that using a little array. And here we go. We just name the thing, So name underscore. Search, comma, I d underscore search. And these need to be in the right order. So we want this one to be used first here and this one to be used second here. So we list this one first in this one second, right? Okay, So now if we save this, come back here. Break out. Clear screen, run This guy. We should get those three records again. John Elder, Tim and Tina. Pretty simple, straightforward. You know, you may or may not want to do something like this, but, um, it is a little bit more complicated cause you need to keep track of, you know, with what's first with second here and here. You have to define these things up here. But generally speaking, this is a more, I don't know, elegant way to do it easier instead of having this whole line here stretch on and on and on . This is just a better way to do. And so, uh, just a little quick tip not to labour it or anything, but wanted to let you know that you could do that. So that's all for this video. In the next video, we're going to start looking at ordering our results. We're gonna look at order by and that will be in the next video. 21. Node mysql 21 Order By: OK in this video. I want to talk about ordering things. So we've just been sort of pulling stuff out of the database and slapping it up on the screen. We can actually order by lots of different things. And that's what we're gonna look at in this video. So I'm gonna head over here and let's rename this order dot Js. Okay, so let's change this to order by Okay, so clean this up a little bit real quick. Boom, boom. And get rid of this stuff from the last video. Okay? We also don't need this fields thing anymore. You can have it on there if you want, but you don't have to. We're not gonna use it for anything. So no real reason to have it. So Okay, now let's get rid of all of this stuff too, okay? So select everything from customers. So let's go ahead and save this and just run it to make sure that this is working. I didn't delete something that I shouldn't have clear the screen. All right, So, node, where dot Js know it knowed order dot Js. And yes, I did miss something up. So did I. Dio Ah, we need a comma. Okay, give this another try. Okay, so this is just pulling everything out. And you see, John married temp Tina, and these were listed just numerically in the order that they're in the database. So this is the first item. 2nd 3rd 4th 5th and six. So we can order by just about anything. And it's pretty simple. We just call, see from customers. We could just say order by and let's say name. We want to order them by name. Well, what does that mean exactly? Well, let's run it and see. Okay, so here we have John, Laura, Mary, Steve, Tim, and Tina. The ideas. Air 15 to 63 and four. Whereas before the ideas were 123456 Right, So we're ordering by the name, and in this case, it's doing alphabetically. So Jay comes before l comes before M comes before s comfort for T I am comes before t i n. So it's just straight up alphabetical now. OK, that's fine. But maybe we want to do the opposite of alphabetical. How would we do that? Well, just pull this up here in order by name and alphabetical is a sending So from a to Z your like going up a sending descending is going down That's like from Z toe A So we can change this to descending now In the last query, it was actually this a sending but a sending is default so you don't have to type it in So we want to do the opposite We just put descending So let's save this Come back here and run it again And now we have the opposite Tina is first instead of last. Tim, Steve, John Elder is last instead of first. Is it pretty simple? So, like I said, you can, um, order these things by just about anything you want. So we're ordering by name, right? You could select Well, I mean, you know, you could you could do I d If we save this, it's clear this screen here So we're descending. Descending is high toe low. So high six down to one Or we could change this. You could just take it off And that means a sending or you can actually designated a sending If we save this break out of here, run it again in here. We get the opposite. 123456 Right. So, um, pretty simple, pretty straightforward. Not a whole lot to order by, but, uh, just sort of interesting. Now, we could kind of be crazy here. We could select, uh, name from customers and then do it descending my I d see if this works. So now notice we're getting the names because we're ordering by the names, But while we're selecting the names, but we're ordering them by the i ds, even though we don't have the i d. S. Right. We didn't pull that idea information out, but the pull us up. Remember the fields variable that we had in there? It passes the I d in. I believe so. We can, I guess, maybe figure it out through that. Yeah, kind of cool. So, um, interesting meat. Kind of fun. Pretty simple. That's off of this video. In the next video, we're gonna start to look at deleting things from our database 22. Node mysql 22 Delete Record: Okay. This video, I want to show you how to delete stuff from our tables. Let's go up here to file, Save as and let's call this delete J s. Okay, so come down here and let's just Well, first of all, let's just print everything from our database and take a look at it real quick. So see, Node delete, I j. S okay. So we have John Elder, Merce met Tim, Tina, Laura and Steve. Let's say we want to get rid of Tina. Never really liked her. So how would we do that? Well, pretty easy. Um, we just instead of select from we just delete from because it didn't need to type from twice. All right. So delete from customers. Now, this is very important right here. We need to use a where clause where and now. What do we want to delete? Well, you can go like we're name equals Tina. A single quote. Right. You could do that. And that will work. But it's not a good idea because your data mate, your database might have thousands of Tina's right. It could very well have many, many Tina's. So which Tina do you want to delete. You don't want to leave him all, do you? If you do this, it'll delete them all. So we don't want that. So, uh, name is probably not a good thing to use. There is one thing that is unique for each record, and that's the I D field. So if we look, every one of these records has its own unique i d it auto aren't increments. And this is one of the main reasons why we assign this primary key. I d teach records so that we can, you know, determine unique records. It also helps with indexing faster, but we don't really care about that right now, but so we would just use an i d. So we want to get rid of Tina. Tina is I d four. So we can just come back over to our code where I d equals for and you noticed I just put four and not, you know, like that, because four is the number. In general, you don't wrap numbers in quotation marks. So very important to put this wear clause in here. I've seen students in the past accidentally leave all this off delete from customers and and then their entire database, their entire table gets deleted. You don't want that, right? So you definitely want the where I d equals for or whatever. You know, I d you want to delete? So that's going to save this now, The result we get, um, is gonna be not much anything, really. I guess because Well, let's just see from this again. Okay, so it's it's returning that field. Remember that, Fields variable. And this is interesting because it shows the affected rows of one. So one rose affected because we deleted one row. And so that's sort of good to know, I guess. But now if we come back here to our code and let's get rid of this delete and let's go select, let's well, everything from customers. Okay, so let's say this if we head back here and run this again Now we see John, Mary, Tim, Laura and Steve. Tina, it was number four is no longer there it was. 123564 has been deleted. And, uh, I think that's all there is to that. Pretty simple. Just remember to use the where clause because you don't want to delete your entire table. That would be crazy. So, uh, you're going to do it sometime? You're just gonna forget or something. I don't think I've done it myself, but I've definitely seen students do it. So add Don't do that. So that's over this video. In the next video, I'll show you how to update records Had a change of record that already exists. 23. Node mysql 23 Update Records: okay. This video, I want to show you how to update a record that's already been created. It's already sitting there. So you've got something in there, you see an error or you got a customer and they move and they change your address. You need updated anything like that. Anytime you want to make any sort of change is the update statement. So head over to our code. And let's save this as a date dot Js And let's just run this. I just have a select everything from customers. So let's save this and run it real quick, So node update dot Js So here we have 12345 records. Remember in the last video, we deleted Cortina. She's no longer with us. So OK, so now we've got say, John Elder, let's say we want to put John P Elder. I don't know. Whatever. Um, how would we do that? Well, pretty simple. We just use the update statement, and that's a date. So we want to update our customers table, and now we need to set what the thing is so set equals and let's go John P older. And then we use our wear clause. Where, um let's say name equals. I did it again with single quotes. Her name equals John Elder. Right? So we want to find the record that has the name of John Elder, and we want to change it to set it to John P. Elder. So let's save this. Come back here and reload this. So all kinds of errors. What have I done wrong? You have an error near John P. Elder. Oh, you have to designate the field that you wanna change. So set name equal John the older where name equals John Elder. Save this. You come back here. Let's clear this screen, okay? And we get the same fields variable returned and affected. Rose was one. We get this little message. Rose matched. One changed, one with no warnings. So changed row one. Okay, so everything seems to work. Let's come back over here. And I'm just gonna copy this. Uh, let's just commented out. And instead, go far. Sequel equals Select everything. Space, everything from customers. Well, all right. So let's run this to make sure that change actually happened. So close this out. Run it again. And here we see John P. Elder. It has in fact, been changed. So Okay, we can do that. But all right, let's comment this out and uncommon This, like I said in the last video, really did a thing searching for and switching out a thing based on a name where name equals John Elder is not a good idea. We know in the last video we should instead use an i d. So let's go ahead and change this back where I d equals one. We want to set this name back to just regular John. Older came to my senses. Don't want to use my middle initial. She's crazy. Okay, so update customers set name equal John Elder, where i d is one. So what this is going to do is gonna find the record that has idea of one is going to change the name from John P. Elder to John Elder. And that should work. Go and save this back here. Clear the screen. Reload. Okay, That seems to have done. It's thing Rose Mashed. One changed one. Everything seems affected. Rose one changed. Rose one already. Let's come back here. Comment this out. Uncommon this Run it again to make sure that change actually happened. And boom, we're back to regular old John Elder. So a pretty simple, pretty straightforward and, uh, very cool. So that's all for this video. In the next video, I'll show you have to limit the results that you are returned and that will be in the next video. 24. Node mysql 24 Limit Records: Okay. This video, I want to show you how to limit the number of results Little returned. So we only have We had six and we have five records in our entire database, so it's not a big deal, But like I've said many times, you could have thousands, hundreds of thousands, millions of records in your database, and you might not necessarily want to return all of them. You might want the top 100 of a thing or the top 1000 of a thing or of half of all of the stuff. Whatever. How do you do that? Well, it's pretty simple. You just use the limit function. So let's come up here and let's save this as limit dot Js and we want Teoh limit the results. Okay, so what we want to dio is actually let's just get rid of that. An uncommon this. So we want to select all from customers, right? But we only want let's say to, right, we don't have a lot to work with here, so we gotta put two so limit to All right, save this. Come back here and let's a node limit the Js and it returns two records. The first too. If you want the last two, you could order by at the end of that. And that will work. Yes, we could just do that real quick. Order by Good idea. Spoke by right order by, um, I d and let's go descending. So we want the last two, right? Save this and run it. Whoa! We have all kinds of errors. What in the world did it? Oh, order by I d descending. But that first boom limit to okay where all this unruly air messages boom. So now we get six and five. Which of the last two items sorted by? Ordered by i d descending. Right. So that's really all there is to it now, actually, haven't tried this before, but in other programming languages here, this order by thing, in other programming languages, you can use percentage percentage is 50% limit, 50%. I'm not sure if you could do it with this. Let's run it and see, do a lot of coding amongst a lot of different platforms. So I've used Post Press regular sequel my sequel. I get him mixed up every once in a while, so I'm not sure if this won't now doesn't work, so you have to actually use a number. So limit to, for instance, Clear Run 12 Okay, so can't use percentages, I guess. That's good to know, though, So we've discovered that Just use the actual numerical value that you want to return, and you should be good to go. So that's a limit. In the next video, I want to show you had to delete a table. Lots of fun. We leave this to the end because once it's deleted, it's deleted, so we'll look at the leading tables in the next video. 25. Node mysql 25 Drop Table: all right. In this video, we're going to delete our table. My favorite thing in the world. The leading tables love it always. This table is nonsense. We have five records. There's nothing to it at all. But still, before I do this, I'm gonna get a little tingle like don't do it. Don't do it. I don't know. It's just psychological. I have a hard time dropping tables, the leading tables, and that's what we're gonna be doing dropping a table in database world. When you delete a table, you're not deleting it. You're dropping it from the database Means the same thing. It deletes it is Just call it dropping a table. So let's come up here to our file and save this as drop dot Js. All right, so here we go. You ready that over to our sequel statement here, and we want to drop table and then just name the table. So customers, right now, this is the last bit of sequel we're gonna dio and I've sort of emphasize this earlier. All of these sequel commands air Very simple, right. Excuse me. Drop table means drop table. Select means select. You know where Klaus order by limit. Whenever you want to do a thing, it's very descriptive. We want to drop the table. So we talk. Drop table is not a lot of stuff to memorize with sequel, which is really kind of nice. But we only bet alone. We've gone over that already. I'm just stalling because I'm scared to drop this table. I hate tropic tables. It it's so permanent. It lasts forever. We're dropping a table. OK, so here we go. Save it back over here. Node. Trump Touch. Yes. Oh, okay. Connected the database. Okay, we get the same fields thing. Uh, affected. Rose zero serviced at zero. Change rose. Zero message. Nothing. So did this thing get dropped or not? I don't know. Let me see here when we pull up hp my men. All right, let's pull this over here. Oh, all right. We looked at PHP. Mind men before sort of user name was route R. Password was blank. Log in here and see. Oh! Oh. Misspelled route. Uh, okay. All right. So here is our no db database. Notice the database itself. Eyes still there. It's still exists, but the table has been deleted. New tables found in database as because we just dropped it. It's gone forever. We can't get it back, and that's that. So that's how you drop tables. Now there is a slight variation. Let's pull back up code here. We could, For instance, if we save this and ran it again, we're gonna get an air, right? It's clear this screen. Why? Because there's no table were saying Drop the customer's table and there isn't a customer's table. So we're getting this horrible error and okay, that's fine. But we can actually make sure that doesn't happen by using the drop table if exists. Functions statement. I guess you would call it statement. Eso you can do this is probably a better idea. Teoh always use the drop table if exists. You know, syntax, you don't have to. If you know the table you want to delete, that's fine. But now if we save this and run it, we're not gonna get that same error message. We're just gonna get this same fields thing. There's a warning, though, this time because there was no database table called customers to delete. So, um, that's probably what that warning is s. Oh, that's cool. So that's dropping tables. I want too bad it's gone. It's gone forever. Just remember, it's permanent. You can't get these backwards there dropped. They drop into nothingness into the void. They're gone forever. So that's all for this video. In the next video, I'll say a few more words, tell you a few things, and we'll wrap this up. 26. Node mysql 26 Bonus: All right. So that is the course. You are now fully fluent in node. My sequel. You know, all the basics. All the basic stuff. Of course, you can learn more database stuff, always. But this is a basic intra, of course, given all the tools just to get, you know, to get started, understand the basic concepts, insert inserting things in, taking things out, creating tables, connecting to node programmatically, you know, formatting the results a little bit, stuff like that. So I hope you enjoyed the course. Had a lot of a lot of fun teaching it. This is, uh it's a pretty fun subject. I like node in the database stuff. Databases get a bad rap. You know, people tend to think that their, ah, lot harder than they are. And they're really not. I think I hope you've learned in this course they're pretty simple sequel itself. The language is very simple. It's just very, uh, you know, conversational Select from order by, you know, pretty simple, pretty straightforward. You just have to memorize all the little things. Don't even really need to do that. You just look it up when you need to. Actually, so Yeah, how that goes as a thank you for sticking it out through this course, I want to show you my website, Kotomi dot com, and give you a super duper coupon code to give you a massive amount of money off my membership. So this my website, I have all my courses here. I've got, like, almost 40 courses, and we'll look at them in a second. But membership is usually $49 that is all my courses. Unlimited access. It's not like a recurring fee you pay at one time, and that's all I've written several Amazon number one bestselling coding books on ruby on rails and some other things. Ph. B. You get the PdF versions of all of those for free. You get access to me. You can ask me questions access to other students. You can interact and talk with them. It's just a really cool community of got over 50,000 students, and if you click on this enroll today, see this total membership, usually 49 bucks. If you click here and click this little coupon code thing and typing you to me, it will knock off another $22 So you pay just $27 for all of my courses. And every time I release a new course and I try and release a new course at least every couple of weeks or so, sometimes sooner you get those for free, they just pop right up in your account. You have to do anything. It just updates and you get it. So really good. Value $27. Basically, I just have to charge us something to cover my band with. Cause video costs a lot of money to stream online's I've got to cover that cost. You know, you've already bought something from me. So I'm not. I don't want to, like, bring a bunch of money out of you, but I still have to cover my costs. So that's why you know I'm charging something, but this is just about as cheap as you can get. $27. It's just a no brainer. Uh, take a look at all the courses I have have ruby on rails, courses, some or all of them. Here we create a clone of the website Pinterest. Here we create a stock market app, um, to do list app with ruby on rails, a crypto currency portfolio app with ruby on rails. A lot of fun. Cryptocurrency news website with ruby on rails We got a bunch of python stuff and python Django. Django is the framework for python. So here we have just a intro Django Course. Here we're building a Cryptocurrency portfolio app with hi thon. This is actually a desktop software. It's not like a Web browser type things that's pretty cool. His, ah, just a intro. JavaScript core so earlier in this course of when we were doing the four Loop. But that was confusing to you if the arrays were confusing to you, take this JavaScript course. It's super easy to hours long. It explains all the basics of Java script. Um, more Django to do list. Here's a sequel course. Microsoft Sequel If you want to learn more about basic sequel stuff, that's kind of cool. Basic Ruby programming create a superhero name generator website with ruby on rails, a ruby game development. That's kind of cool. How to install Ruby on rails on the windows, just a short course, because that's kind of confusing to a lot of people. We got some PHP courses. Couple of those how to push stuff to Roku for third party Web hosting. We got steam it Cryptocurrency. That's an interesting when you get paid to Blawg Michael Moore PHP course on you bunt to Lennix. If you've heard of Lennox and you don't know what it is or why people use it, that's a good course for you. If you want to be a developer programmer, coder and you might want to use Lennox Blogger WordPress. Build some HTML CSS websites and S t o course More PHP Here is a using my sequel databases with Python Course. Just like this course that you just took on Lee with Python Cool. You know, marketing. A basic HTML course Here is a Internet Posts Crest sequel with P, P. G and Men, which is kind of cool. Just another form of sequel, another database that people use. Here's bootstrap, which is a CSS framework, and here's an intercourse and just knowed if you just want to learn how to build websites with notes, so $27 you get all of these courses one time fee. Every time I add a new course, you get it. Get all my books, you can ask me questions. It's just really cool. But if you like taking courses at U Timmy, go to john elder dot com Forward slash you know me. This is just my personal website, and I list all of the the same exact courses that I have on my Kotomi website. But here they are with links that you can watch them on. You know me now each of these has a coupon code. So you only pay, I think 99 for something like that for each of these. Now this starts to add up. If you take four or five of these courses, all of sudden you're in for 50 bucks. You might as well have just signed up for my Kotomi website and watch them all in there for $27. But to each his own, maybe have a bunch of, you know, me credit credits or gifts that somebody gave you. You want to watch a course on you know me. Here's all my all those same courses listed there a nice, nice one page sort of spot. So how are we signed up? Whatever you do, I hope to see you in another one of my courses or 10. They're all like this pretty much just me jabbering on and being stupid and explaining things. The best is I know how I'm available to answer questions obviously, wherever you take my courses and always very happy to do that. But, uh, check it out. It's $27. You can even buy a pizza for that anymore. It's kind of ridiculous. Uh, yeah. So anyway, my name is John Older from kota me dot com had a great time teaching this course, and we'll see in the next one.