mysqli::options

mysqli_options

(PHP 5, PHP 7, PHP 8)

mysqli::options -- mysqli_optionsSet options

Description

Object-oriented style

public mysqli::options(int $option, string|int $value): bool

Procedural style

mysqli_options(mysqli $mysql, int $option, string|int $value): bool

Used to set extra connect options and affect behavior for a connection.

This function may be called multiple times to set several options.

mysqli_options() should be called after mysqli_init() and before mysqli_real_connect().

Parameters

mysql

Procedural style only: A mysqli object returned by mysqli_connect() or mysqli_init()

option

The option that you want to set. It can be one of the following values:

Valid options
Name Description
MYSQLI_OPT_CONNECT_TIMEOUT Connection timeout in seconds
MYSQLI_OPT_READ_TIMEOUT Command execution result timeout in seconds. Available as of PHP 7.2.0.
MYSQLI_OPT_LOCAL_INFILE Enable/disable use of LOAD LOCAL INFILE
MYSQLI_INIT_COMMAND Command to execute after when connecting to MySQL server
MYSQLI_SET_CHARSET_NAME The charset to be set as default.
MYSQLI_READ_DEFAULT_FILE Read options from named option file instead of my.cnf Not supported by mysqlnd.
MYSQLI_READ_DEFAULT_GROUP Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE. Not supported by mysqlnd.
MYSQLI_SERVER_PUBLIC_KEY RSA public key file used with the SHA-256 based authentication.
MYSQLI_OPT_NET_CMD_BUFFER_SIZE The size of the internal command/network buffer. Only valid for mysqlnd.
MYSQLI_OPT_NET_READ_BUFFER_SIZE Maximum read chunk size in bytes when reading the body of a MySQL command packet. Only valid for mysqlnd.
MYSQLI_OPT_INT_AND_FLOAT_NATIVE Convert integer and float columns back to PHP numbers when using non-prepared statements. Only valid for mysqlnd.
MYSQLI_OPT_SSL_VERIFY_SERVER_CERT Whether to verify server certificate or not.

value

The value for the option.

Return Values

Returns true on success or false on failure.

Errors/Exceptions

If mysqli error reporting is enabled (MYSQLI_REPORT_ERROR) and the requested operation fails, a warning is generated. If, in addition, the mode is set to MYSQLI_REPORT_STRICT, a mysqli_sql_exception is thrown instead.

Examples

See mysqli_real_connect().

Notes

Note:

MySQLnd always assumes the server default charset. This charset is sent during connection hand-shake/authentication, which mysqlnd will use.

Libmysqlclient uses the default charset set in the my.cnf or by an explicit call to mysqli_options() prior to calling mysqli_real_connect(), but after mysqli_init().

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top