FiveM Scripting 9 - Setting up MYSQL Database and Inserting Values in it.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right what is it guys my name is zuo from java today we're gonna be doing some I'm gonna be using MySQL async and 5 m and showing you how to save values players in your database so I'm you're gonna need a couple you're gonna need to install a couple things like MySQL async the library and also Sam also before we go into it the code that we write all of it will be you or will be in the description below so yeah also gonna need install my 5mm MySQL ASIC I'll have these I have all these links to the description below for you guys to check out so just click download I have it downloaded it'll download it some different download again just for you guys it involves downloading you're also going to need zamp so basically this amp is it's it's what we use to run our database with if you have some other means of doing that go right ahead unused your way it's just yeah just this is first simpler people who don't really know what they're doing so I'm gonna open understand because I haven't already haven't installed if you have X's on any of these just click on them and then click yes to install it you basically just need a pachi in Maya skills I'm gonna start both of these you know so I'm gonna put this to the side and and with this rar file also just move it to your desktop and believe this and I'm just going to show you rename it to my my SQL ace okay so that should be good we're gonna move that into our server folder as this is a resource for the MySQL library so while this is running we're gonna need to set up our database for actually saving the values so you know we won't go through in the air so to click on admin on the MySQL part and then it should get this thing to a PHP myadmin so we're gonna go to databases and I actually have this already here I'm going to delete my 5m or delete this file and database or you know we'll just we'll create a new one we're gonna call it test actually not we'll call it a 5 m DP you can call whatever you want just remember what you call it or so you created your five M database I'm not gonna be going through a central database and going through the users because that is a lot of dependencies and I'm trying to lift away from dependencies because we're learning how to do it from scratch so no dependencies maybe in the future we'll do a ESX and stuff like that but right now we're just doing from scratch so let's create a table in fact actually we don't even need to do that we are going to make it straight from if you click on the query and you're ain't you're selected in the thighbone database so here's our query we're going to run an SQL script that that's right so we're gonna need to create a table that you know houses all the data that we will potentially be inserting into here so we're gonna create this is a bit of my MySQL here our SQL so just bear with me here so create table we're gonna do main and then open parentheses in here it's close the parentheses to so in here we're going to do I D bar chart which is just basically like a string it's gonna accept the string of only 50 characters and I'll be meld and the default vault because it's not it doesn't really matter we're also gonna be creating and way more in column D were just basically what we're doing right here is we're just creating columns for a database or for our table that is in our database so I'm also just gonna copy that but you know this will house the player names data in that column and then in this column we're gonna have the argument that will potentially save into this bar chart and I will call this we'll have this with 255 characters because we want the string to have a lot of leeway so I have this a default value of all right so I'm supposed to end of it all right so that's basically the I wish you could write here we go we can actually have a colleague equal to lat Swedish see just so we could make a lot easier Jim we're using a no TV Yeah right there and yeah we should we should run that we shouldn't have any issues there we go zero or there we go yeah so if we go nor five M database right here yes we'll have a table in here called main and this is a little will store our ID name and arguments you'll see how this works once we really get into it so now we can actually start setting it up from our server side so let's go into our it's gonna be a bit of a long video and looking at the how long we're into this and it's crazy so in here we're going to drag in MySQL a sink into here it's the library so we're also going to need to go to resources CFG and I'm also just going to start it up here so I'm gonna make a new common call it a MySQL and then we're gonna do start MySQL async so in here we're going to our app after we before we started I want to set I want to make the server connect to our database so I mean basically that's essentially what we're doing here so set Miette mysql underscore connection we'll have that with the server is equal to localhost which is basically our local computer you could type in your IP right here or you know if you're using a different kind of server but yeah also in here I'm gonna do database well basically the semicolon right here this kind of means like a new line so we set up the server is equal to localhost which is our IP and then data base is equal to five I'm just like we called it and then user ID is equal to root that's the default one you don't have a password if you just install it from safe by default but if you were to have a password on your database I think it goes a sword is equal to whatever your password is sorry so then right there that should be connected when once we actually run it but we need to actually use a we can actually create the script now which is fun part all right so let's go neural resources I'm gonna make a new resource called MySQL you can call whatever you want like always we should be familiar with setting up a resource and you our resource underscore underscore which is got two underscores and then in here we're going to have a resource manifest you're gonna need the code right here the resource manifest if you don't want to type that out we're gonna need that I think I don't really know I think it's for server event so you need those four and since we're dealing with a lot of server-side stuff this episode I'm gonna have the resource manifest right there I'll put the put all this in the description below for you guys to top so we're gonna have a client script to and then service we're gonna have multiple scripts so to actually do multiple scripts you can do both the server scripts and then open up a table and we can do a server Lula because that's a server and create that and then to actually access the library that we will be using for MySQL we're basically going to just gonna come out and then select this folder to or select that directory so to actually do that just type in add to MySQL MySQL basic just like we renamed that resource this is that we're basically accessing that resources library so we go here and my SQL which is case-sensitive just do that and as you can see it I mean it's part of that resource oh there we go now we can actually open that up I'm gonna open this into new workspace just so you can make new folders so in a resource download that's all set up so I'm going to create a new file and call it to client I'm also going to be creating a server full screen this for you guys and in let's so let's start off with the client all those easy we're basically gonna have like an output so basically you know if it does it's going to say for as a client side things we're gonna do it's going to output saying oh yeah congratulations it your your thing or your your thing has been saved into this database so it'll just be like a little client side of thing which is why we're doing it through a client side so we're just gonna do register in it okay output output putting it t-there's and in here we're going to do but function and in this function as a what are you mix but you can call that whatever passive and then any here we're going to do really good it's a chat message we're gonna have a play a little thing going to be RGB of 0 RG so we're just gonna have Gia's green and then in here we'll say added edit we're gonna join the argument so you'll see how this what we're doing really here after so added into this is a little basically just alert whatever just got added into the database once we call it the deserve a little so let's actually go into our server da lua and check that out so so you can actually use in the server scope you can use register command so let's do that it'll make our lives a lot easier easier it's a registered we're gonna do save slash save and then what's gonna use an argument for this function what I also have passed the source person and I can actually start actually first I'm going to concatenate the strings so if you don't remember from our server events video and we made the announcement command this args gets outputted into a into a table so we'd have to concatenate it so for example it'll it'll output into like hey it'll be something like that and that's how you know the arcs gets output it so we're gonna need to concatenate that so to do that we're gonna do local arcs string is equal to tabled at ARBs herbs comma and we have this little quote here with the space so it'll space it out after we concatenate the strings together make sure to go check that video out if you don't really understand so now we can actually we're gonna query the database through here and insert the values that we're going to do here now so my we're gonna start out we're gonna start this off with MySQL dot may sink and then fetch all and then in here I don't know I just use fetch all I'm pretty sure that's not right but it works so I guess so this is basically SQL this part right here's SQL in the string so just bear with me here so insert we're gonna be inserting into the table name that we just created we call that name right and then we're gonna be using the columns the columns that we made so there was an ID there was a name there's also cars and like like your ID name and orgs right here so I'm just gonna be writing that down here and then we're gonna need it values to actually parrot with from the game so we can actually communicate together through the game something like that it's a source it's basically divining kind of like defining variables and SQL so arts that that that should be fun so basically what we're gonna want to do after here is we're going to you can just add a comma here and I'm going to I'm going to open up a table here that has we're gonna open brackets and then we're gonna say at what do we do first name so our source is that source is equal to yeah it's it's kind of weird but you just got to do it this is like an format we're gonna open up another one and it's name is equal to get player passing the source so it'll just get the players name through that and then we're also gonna need another one it's defined the last one which is args and then are basically just can be equal to that this little art string right here so we'll be into there so then after that we're gonna comma and then through all of this big function here comma and then we're going to need to call back a function so function and then the results of this will basically output the result so then okay well when that's done so then what you're gonna want to do is trigger went so basically what we just made here it's a trigger client event source because we're we're basically saying we're gonna trigger it to the person that just saved it all the way to the person and I'm going to make this the last parameter just like we did here argument I'm gonna make this green so only the player or so we can see that person that made it and then it's gonna be green so I'm going to join the strings with it was a string so basically what that just saved and then I'm also gonna have it in to 0 which makes it white again so this makes whatever the arc string is green and then it'll change it back to white once it's done at going out the arg string which is just a chat message on your chat box and also i forgot to end function here so yeah that should be it I'm gonna go into the server now I think that should be it basically we did that right and I'm going to show you how this works so let's start that up now tonight make it start SQL AC I forgot to start the resource that we just made so let's go into our resources that CFG and let's start the resource that we just made which I called MySQL so I save that now I actually see you in the server alright a little mistake I called it server scripts or without the T you need to see in there I it's it's like this I don't know what I called or I don't know why I did that I guess it was just a Miss click that I'll see in the server now it's sorry about that yeah alright so I'm in my server and we should do slash safe safe should work somebody such say this would you save and that's a success now if we go to our little database here refresh it yep there we go this is it right here so zua this should be in our database now do it again you know it'll it'll just keep going down and that in our next message MySQL video I'm going to talk about getting values and echoing out on the screen and whatnot if you guys want more of these kinds of tutorials make stuff like it really helps us out if you'd like it you know and subscribe so thank you guys for watching sorry this is a long one I just wanted to try to explain everything as it is a little complicated so you guys crossing and yeah goodbye
Info
Channel: Jeva
Views: 136,812
Rating: undefined out of 5
Keywords: jeva, fivem, fivem scripting, fivem modding, gta v modding, gta v scripting, how to code gta 5, mysql, gta v mysql, fivem mysql, fivem database, zua, zuacp, wesley, jeva time, jeva.xyz, learn how to fivem, fivem tutorial, fivem script, fortnite
Id: SenSzEgnvPE
Channel Id: undefined
Length: 18min 51sec (1131 seconds)
Published: Mon Dec 17 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.