---
name: "Rose::DB::MySQL"
section: "3pm"
platform: "linux"
package: "librose-db-perl"
version: "0.786-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Rose::DB::MySQL"
---

# Rose::DB::MySQL(3pm)

MySQL driver class for Rose::DB.

## NAME

Rose::DB::MySQL - MySQL driver class for Rose::DB.

## SYNOPSIS

```
  use Rose::DB;
  Rose::DB->register_db(
    domain   => 'development',
    type     => 'main',
    driver   => 'mysql',
    database => 'dev_db',
    host     => 'localhost',
    username => 'devuser',
    password => 'mysecret',
  );
  Rose::DB->default_domain('development');
  Rose::DB->default_type('main');
  ...
  # Set max length of varchar columns used to emulate the array data type
  Rose::DB::MySQL->max_array_characters(128);
  $db = Rose::DB->new; # $db is really a Rose::DB::MySQL-derived object
  ...
```

## DESCRIPTION

Rose::DB blesses objects into a class derived from Rose::DB::MySQL when the driver is "mysql".  This mapping of driver names to class names is configurable.  See the documentation for Rose::DB's **new()** and **driver\_class()** methods for more information.

This class cannot be used directly.  You must use Rose::DB and let its **new()** method return an object blessed into the appropriate class for you, according to its **driver\_class()** mappings.

Only the methods that are new or have different behaviors than those in Rose::DB are documented here.  See the Rose::DB documentation for the full list of methods.

## CLASS METHODS

- **coerce\_autoincrement\_to\_serial \[BOOL\]**

  Get or set a boolean value that indicates whether or not "auto-increment" columns will be considered to have the column type  "serial."  If true, "integer" columns are coerced to the "serial" column type, and "bigint" columns use the "bigserial" column type.  The default value is true.

  This setting comes into play when Rose::DB::Object::Loader is used to auto-create column metadata based on an existing database schema.

- **max\_array\_characters \[INT\]**

  Get or set the maximum length of varchar columns used to emulate the array data type.  The default value is 255.

  MySQL does not have a native "ARRAY" data type, but this data type can be emulated using a "VARCHAR" column and a specially formatted string.  The formatting and parsing of this string is handled by the format\_array and parse\_array object methods.  The maximum length limit is honored by the format\_array object method.

- **max\_interval\_characters \[INT\]**

  Get or set the maximum length of varchar columns used to emulate the interval data type.  The default value is 255.

  MySQL does not have a native "interval" data type, but this data type can be emulated using a "VARCHAR" column and a specially formatted string.  The formatting and parsing of this string is handled by the format\_interval and parse\_interval object methods.  The maximum length limit is honored by the format\_interval object method.

## OBJECT METHODS

- **mysql\_auto\_reconnect \[BOOL\]**

  Get or set the mysql\_auto\_reconnect database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_bind\_type\_guessing \[BOOL\]**

  Get or set the mysql\_bind\_type\_guessing database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_client\_found\_rows \[BOOL\]**

  Get or set the mysql\_client\_found\_rows database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_compression \[BOOL\]**

  Get or set the mysql\_compression database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_connect\_timeout \[BOOL\]**

  Get or set the mysql\_connect\_timeout database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_embedded\_groups \[STRING\]**

  Get or set the mysql\_embedded\_groups database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_embedded\_options \[STRING\]**

  Get or set the mysql\_embedded\_options database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_enable\_utf8 \[BOOL\]**

  Get or set the mysql\_enable\_utf8 database handle attribute.  This is set directly on the dbh, if one exists, by executing the SQL `"SET NAMES utf8"`.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_enable\_utf8mb4 \[BOOL\]**

  Get or set the mysql\_enable\_utf8mb4 database handle attribute.  This is set directly on the dbh, if one exists, by executing the SQL `"SET NAMES utf8mb4"`.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_local\_infile \[STRING\]**

  Get or set the mysql\_local\_infile database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_multi\_statements \[BOOL\]**

  Get or set the mysql\_multi\_statements database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_read\_default\_file \[STRING\]**

  Get or set the mysql\_read\_default\_file database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_read\_default\_group \[STRING\]**

  Get or set the mysql\_read\_default\_group database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_socket \[STRING\]**

  Get or set the mysql\_socket database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_ssl \[BOOL\]**

  Get or set the mysql\_ssl database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_ssl\_ca\_file \[STRING\]**

  Get or set the mysql\_ssl\_ca\_file database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_ssl\_ca\_path \[STRING\]**

  Get or set the mysql\_ssl\_ca\_path database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_ssl\_cipher \[STRING\]**

  Get or set the mysql\_ssl\_cipher database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_ssl\_client\_cert \[STRING\]**

  Get or set the mysql\_ssl\_client\_cert database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_ssl\_client\_key \[STRING\]**

  Get or set the mysql\_ssl\_client\_key database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

- **mysql\_use\_result \[BOOL\]**

  Get or set the mysql\_use\_result database handle attribute.  This is set directly on the dbh, if one exists.  Otherwise, it will be set when the dbh is created.  If no value for this attribute is defined (the default) then it will not be set when the dbh is created, deferring instead to whatever default value DBD::mysql chooses.

  Returns the value of this attribute in the dbh, if one exists, or the value that will be set when the dbh is next created.

  See the DBD::mysql documentation to learn more about this attribute.

### Value Parsing and Formatting

- **format\_array ARRAYREF \| LIST**

  Given a reference to an array or a list of values, return a specially formatted string.  Undef is returned if ARRAYREF points to an empty array or if LIST is not passed.  The array or list must not contain undefined values.

  If the resulting string is longer than max\_array\_characters, a fatal error will occur.

- **format\_interval DURATION**

  Given a DateTime::Duration object, return a string formatted according to the rules of PostgreSQL's "INTERVAL" column type.  If DURATION is undefined, a DateTime::Duration object, a valid interval keyword (according to validate\_interval\_keyword), or if it looks like a function call (matches `"/^\w+\(.*\)$/"`) and keyword\_function\_calls is true, then it is returned unmodified.

  If the resulting string is longer than max\_interval\_characters, a fatal error will occur.

- **format\_set ARRAYREF \| LIST**

  Given a reference to an array or a list of values, return a string formatted according to the rules of MySQL's "SET" data type.  Undef is returned if ARRAYREF points to an empty array or if LIST is not passed.  If the array or list contains undefined values, a fatal error will occur.

- **parse\_array STRING \| LIST \| ARRAYREF**

  Parse STRING and return a reference to an array.  STRING should be formatted according to the MySQL array data type emulation format returned by **format\_array()**.  Undef is returned if STRING is undefined.

  If a LIST of more than one item is passed, a reference to an array containing the values in LIST is returned.

  If a an ARRAYREF is passed, it is returned as-is.

- **parse\_interval STRING**

  Parse STRING and return a DateTime::Duration object.  STRING should be formatted according to the PostgreSQL native "interval" (years, months, days, hours, minutes, seconds) data type.

  If STRING is a DateTime::Duration object, a valid interval keyword (according to validate\_interval\_keyword), or if it looks like a function call (matches `"/^\w+\(.*\)$/"`) and keyword\_function\_calls is true, then it is returned unmodified.  Otherwise, undef is returned if STRING could not be parsed as a valid "interval" value.

- **parse\_set STRING \| LIST \| ARRAYREF**

  Parse STRING and return a reference to an array.  STRING should be formatted according to MySQL's "SET" data type.  Undef is returned if STRING is undefined.

  If a LIST of more than one item is passed, a reference to an array containing the values in LIST is returned.

  If a an ARRAYREF is passed, it is returned as-is.

- **validate\_date\_keyword STRING**

  Returns true if STRING is a valid keyword for the MySQL "date" data type.  Valid (case-insensitive) date keywords are:

  ```
      curdate()
      current_date
      current_date()
      now()
      sysdate()
      00000-00-00
  ```

  Any string that looks like a function call (matches /^\\w+\\(.\*\\)$/) is also considered a valid date keyword if keyword\_function\_calls is true.

- **validate\_datetime\_keyword STRING**

  Returns true if STRING is a valid keyword for the MySQL "datetime" data type, false otherwise.  Valid (case-insensitive) datetime keywords are:

  ```
      curdate()
      current_date
      current_date()
      current_time
      current_time()
      current_timestamp
      current_timestamp()
      curtime()
      now()
      sysdate()
      0000-00-00 00:00:00
  ```

  Any string that looks like a function call (matches /^\\w+\\(.\*\\)$/) is also considered a valid datetime keyword if keyword\_function\_calls is true.

- **validate\_timestamp\_keyword STRING**

  Returns true if STRING is a valid keyword for the MySQL "timestamp" data type, false otherwise.  Valid (case-insensitive) timestamp keywords are:

  ```
      curdate()
      current_date
      current_date()
      current_time
      current_time()
      current_timestamp
      current_timestamp()
      curtime()
      now()
      sysdate()
      0000-00-00 00:00:00
      00000000000000
  ```

  Any string that looks like a function call (matches /^\\w+\\(.\*\\)$/) is also considered a valid timestamp keyword if keyword\_function\_calls is true.

## AUTHOR

John C. Siracusa (siracusa@gmail.com)

## LICENSE

Copyright (c) 2010 by John C. Siracusa.  All rights reserved.  This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
