mysql_options()
int mysql_options(MYSQL *mysql, enum mysql_option option, const char *arg)
Can be used to set extra connect options and affect behavior for a connection.
Should be called after mysql_init() and before
mysql_connect() or mysql_real_connect().
The option argument is the option that you want to set; The arg
argument is the value for the option. If the option is an integer, then
arg should point to the value of the integer.
Possible options values:@:
| Option | Argument type | Function |
MYSQL_OPT_CONNECT_TIMEOUT | unsigned int clean_docs_mysql clean_docs-php debut.php fin.php index.php menu.php mysql php | Connect timeout in seconds. |
MYSQL_OPT_COMPRESS | Not used | Use the compressed client/server protocol. |
MYSQL_OPT_NAMED_PIPE | Not used | Use named pipes to connect to a MySQL server on NT. |
MYSQL_INIT_COMMAND | char clean_docs_mysql clean_docs-php debut.php fin.php index.php menu.php mysql php | Command to execute when connecting to MySQL server. Will automatically be re-executed when reconnecting. |
MYSQL_READ_DEFAULT_FILE | char clean_docs_mysql clean_docs-php debut.php fin.php index.php menu.php mysql php | Read options from the named option file instead of from `my.cnf'. |
MYSQL_READ_DEFAULT_GROUP | char clean_docs_mysql clean_docs-php debut.php fin.php index.php menu.php mysql php | Read options from the named group from `my.cnf'.or the file specified with MYSQL_READ_DEFAULT_FILE.
|
Note that the group client is always read if you use
MYSQL_READ_DEFAULT_FILE or MYSQL_READ_DEFAULT_GROUP.
The specified group in the option file may contain the following options:@:
| compress | Use the compressed client/server protocol. |
| database | Connect to this database if there was no database in the connect command |
| debug | Debug options |
| host | Default host name |
| init-command | Command to execute when connecting to MySQL server. Will automatically be re-executed when reconnecting. |
| password | Default password |
| pipe | Use named pipes to connect to a MySQL server on NT. |
| port | Default port number |
| return-found-rows | Tell mysql_info() to return found rows instead of updated rows when using UPDATE.
|
| socket | Default socket number |
| timeout | Connect timeout in seconds. |
| user | Default user |
For more information about option files, see 4.15.4 Fichier d'options.
Zero for success. Non-zero if you used an unknown option.
MYSQL mysql;
mysql_init(&mysql);
mysql_options(&mysql,MYSQL_OPT_COMPRESS,0);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"odbc");
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
fprintf(stderr, "Failed to connect to database:@: Error: %sn",
mysql_error(&mysql));
}
The above requests the client to use the compressed client/server protocol and
read the additional options from the odbc section in the my.cnf
file.