DbConnect
Jump to navigation
Jump to search
Available only in MTA SA 1.1.1 r3328 and onwards This function opens a connection to a database and returns an element that can be used with dbQuery
Syntax
element dbConnect ( string databaseType, string host [, string username, string password, string options ] )
Required Arguments
- databaseType: The type of database. There is currently only one supported type: 'sqlite'
- host: The target to connect to. The format of this depends on the database type. For sqlite it is a filepath to a sqlite database file. If the filepath starts with ":/" then the server's global databases directory is used.
Optional Arguments
- username: Not required for sqlite
- password: Not required for sqlite
- options : List of key=value pairs separated by semicolons
Returns
Returns a database connection element unless there are problems, in which case it return false.
Example
This example opens a connection to a sqlite database file in the current resource
local test_db = dbConnect( "sqlite", "file.db" )
This example opens a connection to a sqlite database file in another resource
local test_db = dbConnect( "sqlite", ":resname/file.db" )
This example opens a connection to a sqlite database file in the global databases directory
local test_db = dbConnect( "sqlite", ":/file.db" )
This example opens a connection to a sqlite database file in a sub directroy of the global databases directory
local test_db = dbConnect( "sqlite", ":/example/sub/dir/file.db" )
Requirements
This template will be deleted.
See Also