Jump to content

Something about OOP


Anubhav

Recommended Posts

Hey guyz,

After searching and researching about OOP in 1.4, I found the function list of OOP ( server ).

I wanted to make my scripts easier but I din't understood how to use some functions.

THESE are they -

create (function: dbConnect)

exec (function: dbExec)

query (function: dbQuery)

please help :)

Link to comment

Here is an example

connection = {} 
connection_mt = { __index = connection } 
  
local validDatabaseType = { 
    mysql = true, 
    sqlite = true 
} 
  
function connection:create( databaseType, host, username, password, options ) 
    if databaseType and type( databaseType ) ~= 'string' then 
        outputDebugString ( 'Bad argument @argument #1 Must be string. ', 0, 112, 112, 112 ); 
        return 
    end 
     
    if not validDatabaseType[ databaseType ] then 
        outputDebugString ( 'Bad argument @argument #1 Unvalid datebase type. ', 0, 112, 112, 112 ); 
        return 
    end 
     
    if databaseType == 'sqlite' then 
        username = ''; 
        password = ''; 
    else 
        username = username; 
        password = password; 
    end 
     
    local connet =  
    {  
        type = databaseType, 
        host = host, 
        username = username, 
        password = password, 
        options = options or '', 
        connection = dbConnect( databaseType, host, username, password, options ) 
    }; 
     
    setmetatable( connet, connection_mt ); 
    return connet; 
end 
  
  
function connection:exec( query, ... ) 
    if query and type( query ) == 'string' then  
        return dbExec( self.connection, query, ... ); 
    end 
end 

local myConnetion = connection:create( 'sqlite', 'path' ) 
myConnetion:exec( 'blablabla', blablabla ) 

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