Jump to content

[help]how to make database


spoty

Recommended Posts

Well, you seem new to sql databases. I suggest you start off with SQLite but none the less I'll show you how to create a database using phpmyadmin (should come with xampp if I remember correctly)

1. Navigate to http://localhost/security/xamppsecurity.php and fill in this section, it shouldn't have "current password".

a20748cf16486434d0bb4a25a77684a6.png

Then RESTART THE MYSQL SERVICE after you have set up your password

2. Now that you have your login details set up, navigate to http://localhost/phpmyadmin/ and login with

username; root

password; the password which you set.

3. Click the database tab and it should bring you here;

7110b085c1db5fe4a31c0020727c753d.png

Note; I have an older version of xampp.

Then you type your database name and you're done.

Question; why did you install xampp when you are just using the mysql service?

Link to comment

viewtopic.php?t=42067&f=148

Read that, next you would want to make a table with the following columns:

accountname, drift points

then you'd do something like

  
local handler = mysql_connect("localhost", "root", "password", "database") 
  
local accountname = getAccountName( getPlayerAccount( player ) ) 
local driftpoints = driftpoints 
  
mysql_query(handler, "UPDATE users SET driftpoints = '" .. driftpoints .."' WHERE accountname = '" .. accountname  .. "' ") 

something like that, then on your register script you should make it insert them into the users table or whatever.

Edited by Guest
Link to comment
https://forum.multitheftauto.com/viewtopic.php?t=42067&f=148

Read that, next you would want to make a table with the following columns:

accountname, drift points

then you'd do something like

  
local handler = mysql_connect("localhost", "root", "password", "database") 
  
local accountname = getAccountName( getPlayerAccount( player ) ) 
local driftpoints = driftpoints 
  
mysql_query(handler, "UPDATE users SET driftpoints = '" .. driftpoints .."' WHERE accountname = '" .. accountname  .. "' ") 

something like that, then on your register script you should make it insert them into the users table or whatever.

so i need to put that into my register script? and what you mean whit that? the internal.db?

Link to comment
https://forum.multitheftauto.com/viewtopic.php?t=42067&f=148

Read that, next you would want to make a table with the following columns:

accountname, drift points

then you'd do something like

  
local handler = mysql_connect("localhost", "root", "password", "database") 
  
local accountname = getAccountName( getPlayerAccount( player ) ) 
local driftpoints = driftpoints 
  
mysql_query(handler, "UPDATE users SET driftpoints = '" .. driftpoints .."' WHERE accountname = '" .. accountname  .. "' ") 

something like that, then on your register script you should make it insert them into the users table or whatever.

so i need to put that into my register script? and what you mean whit that? the internal.db?

No, that script wouldn't work alone, it's just to give you an idea of what you need to do.

So you'd make a table called users in your mysql database, then in your register script you'd make it insert the user into the database/table.

then when you want to update driftpoints you'd do

local handler = mysql_connect("localhost", "root", "password", "database") 
  
local accountname = getAccountName( getPlayerAccount( player ) ) 
local driftpoints = driftpoints 
  
mysql_query(handler, "UPDATE users SET driftpoints = '" .. driftpoints .."' WHERE accountname = '" .. accountname  .. "' ") 

Or something simular.

Link to comment
local accountname = getAccountName( getPlayerAccount( player ) ) 
local driftpoints = driftpoints 
  
local handler = mysql_connect("localhost", "root", "kolpol55", "arizonadrift") 
  
function aaa() 
    dbQuery( myCallback, connection, "SELECT * FROM driftpoints" ) 
end 
  
function myCallback(qh) 
    local result = dbPoll( qh, 0 )   -- Timeout doesn't matter here because the result will always be ready 
end 
  
mysql_query(handler, "UPDATE users SET driftpoints = '" .. driftpoints .."' WHERE accountname = '" .. accountname  .. "' ") 

thats what i have now

but its for now just testing

Link to comment
local accountname = getAccountName( getPlayerAccount( player ) ) 
local driftpoints = driftpoints 
  
local handler = mysql_connect("localhost", "root", "kolpol55", "arizonadrift") 
  
function aaa() 
    dbQuery( myCallback, connection, "SELECT * FROM driftpoints" ) 
end 
  
function myCallback(qh) 
    local result = dbPoll( qh, 0 )   -- Timeout doesn't matter here because the result will always be ready 
end 
  
mysql_query(handler, "UPDATE users SET driftpoints = '" .. driftpoints .."' WHERE accountname = '" .. accountname  .. "' ") 

thats what i have now

but its for now just testing

local driftpoints = driftpoints 

erm, you need to set that something.

so you are trying to get driftpoints from internal.db?

and about the error, could you post your meta.xml as well?

Link to comment
hahaha ye first time i make this kinda fail lel never had it before xD

but if i wanne take the drift score from internal.db how can i do that?

You'd use dbPoll and dbQuery

  
    local query = dbQuery ( housedb, "SELECT * FROM drift_points WHERE accountname = ''" .. accountherelol .. "" )  
    local result = dbPoll ( query, -1 )  
     
   local points = result[1]["points"] 
  

Link to comment
hahaha ye first time i make this kinda fail lel never had it before xD

but if i wanne take the drift score from internal.db how can i do that?

You'd use dbPoll and dbQuery

  
    local query = dbQuery ( housedb, "SELECT * FROM drift_points WHERE accountname = ''" .. accountherelol .. "" )  
    local result = dbPoll ( query, -1 )  
     
   local points = result[1]["points"] 
  

so then it sould be something like this

local accountname = getAccountName( getPlayerAccount( player ) ) 
local driftpoints = driftpoints 
  
local handler = mysql_connect("localhost", "root", "kolpol55", "arizonadrift") 
  
function aaa() 
    dbQuery( myCallback, connection, "SELECT * FROM driftpoints" ) 
end 
  
function myCallback(qh) 
    local result = dbPoll( qh, 0 )   -- Timeout doesn't matter here because the result will always be ready 
end 
  
local query = dbQuery ( housedb, "SELECT * FROM driftpoints WHERE accountname = ''" .. accountherelol .. "" ) 
    local result = dbPoll ( query, -1 ) 
    
   local points = result[1]["points"] 
    
mysql_query(handler, "UPDATE users SET driftpoints = '" .. driftpoints .."' WHERE accountname = '" .. accountname  .. "' ") 

Link to comment

hmm i have getting this error now

[2014-10-01 18:23:17] WARNING: drift\Driftdatabase.lua:1: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil] 
[2014-10-01 18:23:17] WARNING: drift\Driftdatabase.lua:1: Bad argument @ 'getAccountName' [Expected account at argument 1, got boolean] 
[2014-10-01 18:23:17] ERROR: drift\Driftdatabase.lua:14: attempt to concatenate local 'accountname' (a boolean value) 

here is the script

local accountname = getPlayerAccount( getPlayerAccount( source ) ) 
local driftpoints = driftpoints 
  
local handler = mysql_connect("localhost", "root", "", "arizonadrift") 
  
function aaa() 
    dbQuery( myCallback, connection, "SELECT * FROM driftpoints" ) 
end 
  
function myCallback(qh) 
    local result = dbPoll( qh, 0 )   -- Timeout doesn't matter here because the result will always be ready 
end 
  
    local query = dbQuery ( housedb, "SELECT * FROM driftpoints WHERE accountname = '" .. accountname .. "' ") 
    local result = dbPoll ( query, -1 ) 
    
   local points = result[1]["points"] 
    
mysql_query(handler, "UPDATE users SET driftpoints = '" .. driftpoints .."' WHERE accountname = '" .. accountname  .. "' ") 

Link to comment
hmm i have getting this error now
[2014-10-01 18:23:17] WARNING: drift\Driftdatabase.lua:1: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil] 
[2014-10-01 18:23:17] WARNING: drift\Driftdatabase.lua:1: Bad argument @ 'getAccountName' [Expected account at argument 1, got boolean] 
[2014-10-01 18:23:17] ERROR: drift\Driftdatabase.lua:14: attempt to concatenate local 'accountname' (a boolean value) 

here is the script

  

You need an event, how else is it supposed to get the player lol.

https://wiki.multitheftauto.com/wiki/Se ... ing_Events

so say you want to make it sync with the mysql database when a player joins, you' do

  
handler = mysql_connect("localhost", "root", "", "arizonadrift") 
  
function playerJoined() 
  local accountname = getPlayerAccount( getPlayerAccount( source ) ) 
  local driftpoints = driftpoints 
  
  
  
    local query = dbQuery ( database, "SELECT * FROM driftpoints WHERE accountname = '" .. accountname .. "' ") 
    local result = dbPoll ( query, -1 ) 
    
   local points = result[1]["points"] 
    
    mysql_query(handler, "UPDATE users SET driftpoints = '" .. driftpoints .."' WHERE accountname = '" .. accountname  .. "' ") 
end 
addEventHandler ( "onPlayerJoin", root, playerJoined ) 
  
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...