private function makeDB() { try { //echo $this->dbstring . "|" . $this->dbuser . "|" . $this->dbpassword; Yii::$app->setComponent('dbTemp', array('class' => 'CDbConnection', 'connectionString' => $this->dbstring, 'username' => $this->dbuser, 'password' => $this->dbpassword, 'emulatePrepare' => true, 'charset' => 'utf8', 'tablePrefix' => '')); $master = new dbMaster(); $master->loadFile("protected/data/main.sql"); //$master->loadFile("protected/data/main-data.sql"); } catch (\yii\db\Exception $e) { $message = $e->getMessage(); echo "Crash and Burn:"; echo "<br>" . $message; exit; } return true; }
public function make() { //make conf file //echo $this->dbtype; //Yii::$app->end(); if ($this->dbtype == 'sqlite') { $str = "'connectionString' => '" . $this->dbstring . "',"; } else { $str = "'connectionString' => '" . $this->dbstring . "',\n 'username' => '" . $this->dbuser . "',\n 'password' => '" . $this->dbpassword . "',"; } $new = (include 'protected/data/config.php'); $new = str_replace("<placeholder>", $str, $new); $handle = fopen('protected/config/install.php', 'w'); fwrite($handle, $new); fclose($handle); //make main db $mysql = "protected/data/main.sql"; if (file_exists($mysql)) { Yii::$app->db->close(); Yii::$app->db->dsn = $this->dbstring; Yii::$app->db->username = $this->dbuser; Yii::$app->db->password = $this->dbpassword; Yii::$app->db->open(); dbMaster::loadFile($mysql); /* $sqlArray = file_get_contents($mysql); //print $sqlArray; $cmd = Yii::$app->db->createCommand($sqlArray); //$cmd->execute(); try{ $cmd->execute(); } catch(\yii\db\Exception $e){ $message = $e->getMessage(); print $message; }*/ } else { throw new \yii\db\Exception(Yii::t('app', 'Cant find Company template file unable to create database')); } return true; }
private function createDb() { $yiiBasepath = Yii::app()->basePath; //$mysql=$yiiBasepath."/data/company-lite.sql"; $master = new dbMaster(); //$master->loadFile($yiiBasepath . "/data/company-lite.sql", Yii::app()->db->tablePrefix); $master->loadFile($yiiBasepath . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "company.sql", Yii::app()->db->tablePrefix); $master->loadFile($yiiBasepath . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "company-data.sql", Yii::app()->db->tablePrefix); }