Jump to content

MySQL script


TrickyTommy

Recommended Posts

connection = dbConnect( "mysql", "dbname="..mySQLDetails["db"]..";host="..mySQLDetails["host"].."", ""..mySQLDetails["acc"].."", ""..mySQLDetails["pass"].."", "share=1" )

function dbQuery(query, values)
	qh = dbQuery(connection, query, values)
end

Hi! I am making a mysql script, and i would not like to do the dbConnect stuff and things like this everytime. But after the query, there might be values, not only just one. So for example in the query, i want to insert 2 things, and it would look like this:
                 -------------------------------------------------string query-------------------------------------------   ---------------------values-------------                                                                    
dbQuery(connection, "INSERT INTO users (username, password) VALUES (?, ?)", Username, md5(Password))

But the password would not be inserted! I know that i'll have to use table. but how?

Link to comment

Sorry, we misunderstood each other. Let me show it to you on the following picture:
jjbKex9.png
I want to make some king of a "useful function", and i would like to use this instead of dbQuery, because the connection was already declared here, and i would not like to declare an other connection in an other script. So i can export the function and use it like exports.db:sqlQuery(string query, variables for the query)

Link to comment
connection = dbConnect( "mysql", "dbname="..mySQLDetails["db"]..";host="..mySQLDetails["host"].."", ""..mySQLDetails["acc"].."", ""..mySQLDetails["pass"].."", "share=1" )

_dbQuery = dbQuery
function dbQuery(query, values)
	return _dbQuery(connection,query,values)
end

 

  • Thanks 1
Link to comment
function sqlQuery(query, ...)
	return dbQuery(connection, query, ...)
end


local Query = sqlQuery ("INSERT INTO test (asd1, asd2) VALUES (?, ?)", "asd1", "asd2")
if Query then outputServerLog ("true") else outputServerLog ("false") end

it is not inserting to the database, however it returns true. what have gone wrong?

Link to comment
function sqlQuery(query, ...)
	return dbQuery(connection, query, ...)
end

iprint(connection, "INSERT INTO test (asd1, asd2) VALUES (?, ?)", "asd1", "asd2")
local Query = sqlQuery ("INSERT INTO test (asd1, asd2) VALUES (?, ?)", "asd1", "asd2")
if Query then outputServerLog ("true") else outputServerLog ("false") end

i might be dumb, and messed it up. not sure if it's correct.

FIXED: re-created the table, it is working now.
 

function sqlQuery(query, ...)
	return dbQuery(connection, query, ...)
end

local Query = sqlQuery ("INSERT INTO test (test1, test2) VALUES (?, ?)", "Successsss 1", "Successsss 2")
if Query then outputServerLog ("true") else outputServerLog ("false") end

 

Link to comment
  • Moderators
function sqlQuery(query, ...)
	iprint(connection, query, ...) -- < iprint here
	return dbQuery(connection, query, ...)
end


-- do the original query function, if something goes wrong then it is not a problem with your utility function.
local qh = dbQuery(connection, "INSERT INTO test (asd1, asd2) VALUES (?, ?)", "asd1 original", "asd2 original")
dbFree ( qh )

-- do yours.
local Query = sqlQuery ("INSERT INTO test (asd1, asd2) VALUES (?, ?)", "asd1", "asd2")
dbFree ( Query )

if Query then outputServerLog ("true") else outputServerLog ("false") end

 

  • Thanks 1
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...