dbConnect | Multi Theft Auto: Wiki Skip to content

dbConnect

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function opens a connection to a database and returns an element that can be used with dbQuery. To disconnect use destroyElement.

Note

Connecting and disconnecting many times can have a performance impact on the server. For optimal performance it is recommended that you use dbConnect only once when the resource starts, and share the connection element with the whole script.

Note

In MySQL 8.0 and later, you can choose between caching_sha2_password , sha256_password , or mysql_native_password for password management. If you opt for caching_sha2_password or sha256_password , SSL is not mandatory but recommended for secure authentication. If you choose mysql_native_password , you can set it as the default authentication plugin: In the mysqld.cnf configuration file, by adding or modifying the following line: default-authentication-plugin=mysql_native_password Using SQL queries (e.g., ALTER USER). In PHPMyAdmin (via the user settings page). Please note that starting with MySQL 9.0, mysql_native_password will no longer be available, and only caching_sha2_password and sha256_password will be supported.

Note

Under certain platforms, for example on Unix-based OSes like Linux, using this function could fail with a debug warning containing "[Could not connect]" accompanied by a prior debug error explaining the problem. In that case you should check the Server Manual to see if you have missed any recommended (best-effort) steps for server set-up.

Syntax

dbConnect ( )

Code Examples

server

This example opens a connection to a SQLite database file in the current resource

test_db = dbConnect( "sqlite", "file.db" )