Skip to content

mysql_connect

imshooter edited this page Nov 29, 2026 · 1 revision

Connect to a database.

The connection is made before the native returns. When it fails, the handle is still given, mysql_errno tells why, and every query tries to connect again, half a second after the first failure and twice as long after each next one, up to five seconds. Unless DUPLICATE_CONNECTIONS is set, the same server, account and database give the handle opened already.

native MySQL:mysql_connect(
    const host[],
    const user[],
    const password[],
    const database[],
    MySQLOpt:option_id = MYSQL_INVALID_OPTIONS
);

With open.mp names, from the same include:

native MySQL:MySQL_Connect(
    const host[],
    const user[],
    const password[],
    const database[],
    MySQLOpt:option_id = MYSQL_INVALID_OPTIONS
);

Parameters

Parameter Description
const host[] Name or address of the server.
const user[] Account to log in with.
const password[] Password of the account.
const database[] Database the queries use.
MySQLOpt:option_id = MYSQL_INVALID_OPTIONS Options from mysql_init_options, or none.

Returns

  • The handle.
  • MYSQL_INVALID_HANDLE when the options do not exist.

Home

Guides

Reference

Functions

Connections
Queries
Cache
JSON cells
ORM
Queries built in pieces
Prepared statements
Batches
Transactions
Passwords
Callbacks

Clone this wiki locally