 Hey everybody, it's Brian and welcome to the 54th lamp tutorial today We're going to be discussing how to actually do all this sequel stuff in PHP as you see We've got our standard sequel select statement here, and we're just going to modify this a little bit We're just going to filter out some rows You can see we just have our rows here, so Not too much different to what we've done before so we're just going to grab this guy whoops Copy that go into our editor here. I'm just going to say Press right turn that into a proper string or it'll complain. There we go So we've got a string which holds our select statement in here and Now what we need to do is actually connect to our database and In the my sequel connect method you see how we have a few things we need to give it here We need to give it a host name port username password etc etc, so We'll give it the Server name whoops One two seven zero zero one is same thing as local host, but I'm just typing it out Give it our username And our password This will return a connection object What we need to do here is Actually see if we have an object, so we're saying if not come on Then we're just gonna say Could not Connect and then we need a reason we're just gonna do my sequel And we're gonna get the error message So if we made it this far, we've actually connected. Uh-oh doesn't like this. What's going on here? Yes Grab my semicolon at the end of that statement. There we go. So if we made it this far means we have a connection Now if you've opened a connection, you should also close it. So the first thing I always do is my sequel Close and the reason why you do that it'll it'll do it automatically But I just like freeing resources as soon as I'm done with them just to reduce overhead And what I mean by it'll do it automatically. I mean when the php interpreter Runs this page and it gets to the point it no longer needs it. It'll close or kill that object But it may not happen for a few seconds. So I actually just like to close it immediately So we have an active connection here. So we're just going to say Echo We are connected And let's see here And it says uh could not connect access denied using password. Yes Save this 1-2-7-0-0-1 Probably help if I don't write password in there. At least we know that we are actually working right here We're connected So once you're connected, then you can actually do something and what we're going to do is use this sequel And we can actually just take this Little guy Cut that and we're just going to paste it down here. That way it makes a little more sense what we're doing Now we're going to actually You know submit the query. So we're going to say result equal my sequel query And We're going to give it to you Now one thing you might notice Is that in our query we are not using the um select database Or the use the use my store. So we're going to jump back in here And actually Tell it to use that we're going to say my sequel Select db or select database and we want to Say my store because that's the name of the database And then we need the connection object and in case you're wondering, yes You can have multiple connections going on at the same time to multiple databases. It's very very powerful So let's save and run this now. Notice how nothing happened on the screen even though we got our result So what is this result? Let's let's examine this It says resource id number three. What is that? Hmm Well, let's take a look at this and we'll say echo Is array Let's see if this is an array Didn't like that either So as you can see it's not a true array. So what we need to do here Is actually Grab a row. So we'll say row equal and we need to say my sequel fetch That's how we're saying fetch array And we're giving it the result So what we're doing is saying take that result Turn it into an array Now this row will be a true array object So let's say Echo See that one right there. That is true So we're going to just basically Play around with this a little bit. We're going to say While We have an array. So we're going to say while we have rows We're just going to echo out some properties from this row We'll echo out the description And we'll echo out the call. Uh, what is it? Yes, the cost My mind was totally wandering. I think it's something work related. I have work on the brain today Let's hate that when you just want to come home and write some code and pesky work always gets in the way So we're just going to add a little html goodness here So you see how you have mark's gun shop chat's gun shop bob's gun shop. Let's actually throw out a Little html goodness here so you can actually see So we have three records. So what was that when we Echoed out this result. Let's do that again just so we can show you what's going on here You kind of need to understand what's going on under the hood resource ID number three So that's actually what's going on is you have a resource id not an actual array and you have to Fetch an array from the list of rows that's returned from the server Sounds complex, but a lot of this stuff happens under the hood So you don't even need to worry about it And because now we have a true array here We don't even need to do this what we can do is just say Extract row and in case I haven't covered this in previous tutorials What extract does is it takes an array And turns them into variables. So now you can say Echo Description Pretty neat, huh? Let's actually get rid of this so you can see that the results did actually change on the screen Say ta-da So what we're doing is we're extracting the array turning it into variables So instead of saying row and then the Element in the array you can just call it as a variable itself and then you can do computations and all sorts of the good stuff on it So pretty neat stuff Pretty effective really really powerful One thing you should note is that The mysql connect and like mysql query and stuff. They're not fully object-oriented So you have to do simple error handling not so much object-oriented error handling I could be wrong about that but Be on the safe side. So that's all for this tutorial. We have covered a lot of ground in this series To be brutally honest unless something major comes up. I'm going to really consider this the last tutorial I am thinking about doing See if I get my web browser to load These virtual machines are so slow bear with me. Anyways, I'm thinking about doing some some frameworks There are a lot of frameworks the problem with frameworks and php is there's so many of them um Like if you just go to go go and type in php frameworks I mean, there's so many of them. It's just mind boggling And like php frameworks is the first link that comes up And I mean this is this isn't even all the frameworks out there. It's just a small subsection of them Some of the more popular ones. Um, I've looked into a couple of these and the problem with Picking a framework is the minute you pick a framework you instantly lose the attention of hundreds of thousands of people For example, if I choose zen Well, then all the people that want to learn yi are going to go away Or if I choose yi all the people that want to learn zen go away And the other problem with a framework is when you start working with a framework, you're really locked into That framework's way of doing things Now there are certain things like a fat free php Um, it's a very lightweight framework That allows you to do it, but it doesn't have a lot of the features. I mean you can see a lot of the feature sets right here like up here Where some of the more popular ones are like cake php um, let's see Yi it's stands for yes. It is it's a little acronym. I've actually played around with you. It's actually really good. Um zen Zen is probably the most popular one, but it is in commercial based meaning If you really want to get into zen you're going to end up spending some money symphony. I've heard is also very good But I've never touched it so That's really all for this tutorial and Pretty much all for this series unless I really get into doing some frameworks once again void realms.com my website You can find the i'm trying to go out there and upload everything I've been so busy with work, but you can find the complete source code to all of my tutorials and then some just go to my website go to tutorials Go to lamp And there they are and all their glory and I want to mention like if you go in here You can download the source code view the video which will appear here in a second Um, if you go to download the source code, there will be an annoying. Hey, please donate now My website's completely donation based if you don't want to download or I'm sorry if you don't want to donate Don't donate just download now But if you do want to donate Go ahead and click there and make a donation Um, been a fun series. I've learned a lot. I appreciate you guys's feedback If you guys really want to see a framework, let me know, but um I don't know it's going to be a hard decision for me not just To do a framework or not, but which framework to do because there's So many of them. I mean you could easily spend the next 10 years doing tutorials on just php frameworks. So That's all. Thank you for watching You