/**
* Constructor.
*
- * @param array $config Configuration options and optional objects:
- * <pre>
- * 'charset' - (string) TODO
- * </pre>
+ * @param array $config Configuration options and optional objects.
*/
public function __construct($config)
{
$this->_cache = new Horde_Support_Stub();
$this->_logger = new Horde_Support_Stub();
- // Default to UTF-8
- if (!isset($config['charset'])) {
- $config['charset'] = 'UTF-8';
- }
-
$this->_config = $config;
$this->_runtime = 0;
}
/**
- * Returns the database character set that query results are in
- *
- * @return string
- */
- public function getCharset()
- {
- return $this->showVariable('character_set_results');
- }
-
- /**
- * Set the client and result charset.
- *
- * @param string $charset The character set to use for client queries and results.
- */
- public function setCharset($charset)
- {
- $charset = $this->_mysqlCharsetName($charset);
- $this->execute('SET NAMES ' . $this->quoteString($charset));
- }
-
- /**
- * Get the MySQL name of a given character set.
- *
- * @param string $charset
- * @return string MySQL-normalized charset.
- */
- public function _mysqlCharsetName($charset)
- {
- $charset = strtolower(preg_replace(array('/[^a-zA-Z0-9]/', '/iso8859(\d)/'), array('', 'latin$1'), $charset));
- $validCharsets = $this->selectValues('SHOW CHARACTER SET');
- if (!in_array($charset, $validCharsets)) {
- throw new Horde_Db_Exception($charset . ' is not supported by MySQL');
- }
-
- return $charset;
- }
-
- /**
- * Returns the database collation strategy
- *
- * @return string
- */
- public function getCollation()
- {
- return $this->showVariable('collation_database');
- }
-
- /**
* List of tables for the db
*
* @param string $name
* @param string $name
* @param array $options
*/
- public function endTable($name, $options=array())
+ public function endTable($name, $options = array())
{
- $opts = array('options' => 'ENGINE=InnoDB DEFAULT CHARSET=' . $this->getCharset());
- return parent::endTable($name, array_merge($opts, $options));
+ $opts = 'ENGINE=InnoDB';
+ if (!empty($options['charset'])) {
+ $opts .=' DEFAULT CHARSET=' . $options['charset'];
+ }
+ return parent::endTable($name, array_merge(array('options' => $opts), $options));
}
/**