DbConnect: Difference between revisions
Jump to navigation
Jump to search
(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...") |
No edit summary |
||
Line 12: | Line 12: | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''databaseType:''' The type of database. There is currently only one | *'''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. | *'''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=== | ===Optional Arguments=== | ||
Line 21: | Line 21: | ||
===Returns=== | ===Returns=== | ||
Returns | Returns a database connection element unless there are problems, in which case it return ''false''. | ||
==Example== | ==Example== |
Revision as of 17:40, 26 October 2011
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