DbConnect

From Multi Theft Auto: Wiki
Revision as of 17:01, 26 October 2011 by Ccw (talk | contribs) (Created page with "__NOTOC__ {{Server function}} {{New feature|3.0120|1.2| '''Available only in MTA SA 1.1.1 r3328 and onwards''' }} This function opens a connection to a database and returns an e...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 support 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.

Optional Arguments

  • username: Not required for sqlite
  • password: Not required for sqlite
  • options : List of key=value pairs separated by semicolons

Returns

Returns an element of type "db-connection" 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