# Class Mysql.mysql

Inheritance graph

Description

  Low level interface to the Mysql database.

  This class enables access to the Mysql database from within Pike.

See also

  Mysql.mysql_result, Sql.Sql

Method create

  `Mysql.mysql Mysql.mysql()`
  `Mysql.mysql Mysql.mysql(`string` `host`)`
  `Mysql.mysql Mysql.mysql(`string` `host`, `string` `database`)`
  `Mysql.mysql Mysql.mysql(`string` `host`, `string` `database`, `string` `user`)`
  `Mysql.mysql Mysql.mysql(`string` `host`, `string` `database`, `string` `user`, `string` `password`)`
  `Mysql.mysql Mysql.mysql(`string` `host`, `string` `database`, `string` `user`, `string` `password`, `mapping`(`string`:`string`|`int`) `options`)`

Description

  Connect to a Mysql database.

  To access the Mysql database, you must first connect to it. This is done with this function.

Parameter `host`

  If you give no argument, or give `""` as host it will connect with a UNIX-domain socket, which can be a big performance gain.

Parameter `options`

  This optional mapping can contain zero or more of the following parameters:

  ``"init_command"` : `string`` | Command to execute on connect.
  ``"timeout"` : `int`` | Timeout in seconds.
  ``"compress"` : `bool`` | Enable compressed protocol.
  ``"mysql_config_file"` : `string`` | Change config file from `"my.cnf"`.
  ``"mysql_group"` : `string`` | Specify additional group to read from config file.
  ``"mysql_named_pipe"` : `bool`` | Use named pipe to connect to server.
  ``"mysql_local_infile"` : `bool`` | Enable use of LOCAL INFILE (security).
  ``"mysql_charset_dir"` : `string`` | Change charset directory.
  ``"mysql_charset_name"` : `string`` | Set connection charset - see `set_charset` for details. The default is `"latin1"`. As opposed to `set_charset`, this way of specifying the connection charset doesn't require MySQL 4.1.0.
  ``"unicode_decode_mode"` : `int`` | Enable unicode decode mode for the connection if nonzero. In this mode non-binary string results are automatically converted to (possibly wide) unicode strings. An error is thrown if the server doesn't support this. See `set_unicode_decode_mode`.
  ``"ssl_key"` : `string`` | Path to SSL-key for use in SSL-communication.
  ``"ssl_cert"` : `string`` | Path to SSL-cert for use in SSL-communication.
  ``"ssl_ca"` : `string`` | Path to SSL-CA for use in SSL-communication.
  ``"ssl_capath"` : `string`` | Path to SSL-CAPATH for use in SSL-communication.
  ``"ssl_cipher"` : `string`` | FIXME
  ``"connect_options"` : `int`` | Options used when connecting to the server. See mysql documentation for more information.

Note

  Some options may not be implemented. Unimplemented options are silently ignored.

Note

  To use SSL-connections, set the SSL-parameters correctly. They correspond to the parameters given to the mysql-client with the same name so make sure that the mysql-client works with SSL and set these parameters to the same values and everything should work. If SSL-options are loaded from a config-file, one may set the connect_options to include CLIENT_SSL.

Note

  If Pike has been built with an old MySQL client lib then it might not be possible to specify some charsets that the server supports with the `"mysql_charset_name"` option. In such cases it's possible that `set_charset` works better (provided the server is 4.1 or newer).