DbConnect

From Multi Theft Auto: Wiki
Revision as of 17:40, 26 October 2011 by Ccw (talk | contribs)
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

Minimum server version 1.1.1-9.03328
Minimum client version n/a

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.1.1-9.03328" />

See Also