. */ /* */ /*************************************************************************************/ namespace Thelia\Install; /** * Class Database * @package Thelia\Install * @author Manuel Raynaud */ class Database { public $connection; public function __construct(\PDO $connection) { $this->connection = $connection; } /** * Insert all sql needed in database * * @param $dbName */ public function insertSql($dbName = null) { if($dbName) { $this->connection->query(sprintf("use %s", $dbName)); } $sql = array(); $sql = array_merge( $sql, $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/thelia.sql")), $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/insert.sql")) ); for ($i = 0; $i < count($sql); $i ++) { if (!empty($sql[$i])) { $this->connection->query($sql[$i]); } } } /** * Separate each sql instruction in an array * * @param $sql * @return array */ protected function prepareSql($sql) { $sql = str_replace(";',", "-CODE-", $sql); $sql = trim($sql); $query = array(); $tab = explode(";", $sql); for ($i=0; $iconnection->query( sprintf( "CREATE DATABASE IF NOT EXISTS %s CHARACTER SET utf8", $dbName ) ); } }