/** * Driver options: * - charset => character encoding to set (default is utf8) * - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html */ public function __construct(Nette\Database\Connection $connection, array $options) { $this->connection = $connection; $charset = isset($options['charset']) ? $options['charset'] : 'utf8'; if ($charset) { $connection->exec("SET NAMES '{$charset}'"); } if (isset($options['sqlmode'])) { $connection->exec("SET sql_mode='{$options['sqlmode']}'"); } $connection->exec("SET time_zone='" . date('P') . "'"); }
/** * Import SQL dump from file - extreme fast. * @param string filename * @return int count of commands */ public static function loadFromFile(Connection $connection, $file) { @set_time_limit(0); // intentionally @ $handle = @fopen($file, 'r'); // intentionally @ if (!$handle) { throw new Nette\FileNotFoundException("Cannot open file '{$file}'."); } $count = 0; $sql = ''; while (!feof($handle)) { $s = fgets($handle); $sql .= $s; if (substr(rtrim($s), -1) === ';') { $connection->exec($sql); // native query without logging $sql = ''; $count++; } } fclose($handle); return $count; }
ERROR_DATA_TRUNCATED=1265;private$connection;function __construct(Nette\Database\Connection$connection,array$options){$this->connection=$connection;$charset=isset($options['charset'])?$options['charset']:'utf8';if($charset){$connection->exec("SET NAMES '$charset'");}if(isset($options['sqlmode'])){$connection->exec("SET sql_mode='$options[sqlmode]'");}$connection->exec("SET time_zone='".date('P')."'");}function
public function rollback() { $this->database->exec('ROLLBACK'); }