Jump to content

mysql problem


Dimos7

Recommended Posts

<meta>
     <script src="server.lua" type="server"/>
	 <export function="_Query" type="server"/>
	 <export function="_QuerySingle" type="server"/>
     <export function="_Exec" type="server"/>
</meta>	 
local connection = nil
addEventHandler("onResourceStart", resourceRoot, function(resource)
      connection = dbConnect("mysql", "databse=mtarp; host=127.0.0.1; port=3306;", "root", "9852174563")
	  if connection then
	     outputDebugString(getResourceName(resource).. ":connected to database.")
		 return true
	  else
	     outputDebugString(getResourceName(resource).. ":unable to connect to database. Please contact Developer.")
		 return false
	  end
   end
)

function _Query(...)
    if connection then
	   local query = dbQuery(connection, ...)
	   local result = dbPoll(query, -1)
	   return result
	else
	   return false
	end
end

function _QuerySingle(str, ...)
    if connection then
	   local result = _Query(str, ...)
	   if type(result) == 'table' then
	      return result[1]
	   end
	else
	   return false
	end
end

function _Exec(str, ...)
    if connection then
	    local query = dbExec(connection, str, ...)
		return query
	else
	   return false
	end
end	

server line 37 dbExec failed; no databse selected

server line 17 dbPoll no database selected

Edited by Dimos7
Link to comment

Read this line:

connection = dbConnect("mysql", "databse=mtarp; host=127.0.0.1; port=3306;", "root", "9852174563")

There's a typo in "database=mtarp" and it shouldn't be database anyway, it should be:

connection = dbConnect("mysql", "dbname=mtarp; host=127.0.0.1; port=3306;", "root", "9852174563")

 

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...