Hello, in this video, I'm going to show you how to insert multiple rows in to your database into your table. So you could theoretically just do this twice, you know, keep doing it, you know, keep doing it, so prepare it and then execute it. But not only is that extra code, it is also, you know, more taxing on on your, on your server because you're constantly, you know, doing loads of submissions, whereas if you think of it like this, imagine if you're have a shopping list, you have five items on now, it's gonna make a shopping list as milk. You know, just the basic stuff. I don't know crisps. And so, doing it like this is the equivalent of going to the shop, wherever it might be, again, the eggs going back, you know, pranam going to them shop again, getting the milk coming back, pulling away and just keep doing it like that.
Whereas what you want to do is have a list Um, you know, items that you need, go there, get the eggs, the milk, the bread, the Chris, the sweet branch, you know, shopping basket, get to the tail pay and go home, do it all in one go. That's a lot better a lot quicker. It's just, I don't I don't see why you would want to do it that way. There's something similar. You can do with databases. So you can essentially begin a transaction.
And this will basically say, these are the things I want to do. And you know, it doesn't really have to just be inserts things. It could be, you know, a bunch of stuff, but probably combining with insert statements, and then you want to execute it. So what you do is you get the connection, you put the transaction, so I'm beginning the transaction. Next, we do connection and you want to say exactly, So I'm going to be executing a particular mumble is an executed straight away and we literally want to do this we want to get hold of this. Put that here to what we'll do okay, that's fine.
And I'm gonna do another one. Do another one so we just do one the ones we want now instead of Darth Vader, only be Yoda we gotta put Darth Plagueis the wise I think this is spell plague this. So plague and then is the plague us and also insert CVS I should be able to spell that See Okay, so there we go da Cydia stop lagers and mobile dot play this is talking to Muslims if master dot play you want to get a correct now Dark Lord and safe a master of da Cydia so you would have been safe master and technically by the time Darth Sidious rolled around he will see if Master Master Master or add order of these and there to actually I definitely just do connection commit and commit what you put there. So if you take a look I don't have any of them that disappeared because I reloaded the page from before.
Okay, but let me show you got nothing there. I do that okay. Getting an error hasn't been added. Let's see what we get. A pair expects at least one statement zero given to me. Okay, so I still need to comment.
So what happened, and yet nothing that I did now if I reload. There we go. It added Darth Vader, Darth Plagueis, Darth Sidious, all in one fell swoop. So you have to do multiple, you know, preparation, then multiple executions, you can just basically prepare it, each statement, and then just committed. So that's a lot more efficient in terms of code. And in terms of, you know, the, the interaction with your database performance.
So that's it for inserting multiple rows. If you have any questions, as usual, please do not message me because I do not want to have any messages. I'm only joking. But obviously, feel free to message me and I will do the best as I can. And I look forward seeing you in the next video.