Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jak ominąć błedy w instalacji bazy z poziomu Root
majka111
post
Post #1





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 7.06.2010

Ostrzeżenie: (0%)
-----


Serdecznie witam

mam mały problem nad którym juz siedzę 3 dzień i czuję że sobie nie poradze z nim szybko.

Mianowicie mam skrypt w którym mam plik odpowiedzialny za instalacje wstepną.

Ten plik ma za zadanie utworzenie bazy danych ale z poziomu Root do którego nie mam dostępu, wgranie tabeli , oraz zapisanie ustawień w plikach.

Wszystko to zrobiłem recznie dodałem baze, tabele , skonfigurowałem pliki ini

a to diabelstwo poniżej nie chce mnie przepuścić do kolejnego kroku

"create admin"


Nie chodzi mi o zmianę całości lecz tylko o przejscie do natępnego kroku INSTALACJI pomimo napotkanych błedów

w którym miejscu pliku mam dopisać jakąś funkcje typu

"jeżeli bład to idz do $this->_redirect('install/create-admin'); "


dziekuję za pomoc




  1. <?php
  2.  
  3. class Install_IndexController extends Zend_Controller_Action
  4. {
  5.  
  6. /* @access Public
  7.   * @var object
  8.   */
  9. private static $installDb = null;
  10.  
  11. /* @access Public
  12.   * @var object
  13.   */
  14. private static $installForm = null;
  15.  
  16. /* @access Public
  17.   * @var object
  18.   */
  19. private static $installMail = null;
  20.  
  21.  
  22. /**
  23.   * @access Public
  24.   * @return void
  25.   */
  26. public function init()
  27. {
  28. self::$installForm = new Model_Install_Form;
  29.  
  30. $config = Zend_Registry::get('configuration');
  31.  
  32. if($config->installed) {
  33. $this->_redirect('index');
  34. }
  35. }
  36.  
  37.  
  38. /**
  39.   * @access Public
  40.   * @return void
  41.   */
  42. public function indexAction()
  43. {
  44. $error = false;
  45. $this->view->databaseConfig = true;
  46. $this->view->config = true;
  47. $this->view->media = true;
  48. $this->view->cache = true;
  49.  
  50. // pre validation Database.ini
  51. if(!is_writable(Zend_Registry::get('siteRootDir').'/application/Configs/Database.ini')) {
  52. $error = true;
  53. $this->view->databaseConfig = false;
  54. }
  55.  
  56. // pre validation Config.ini
  57. if(!is_writable(Zend_Registry::get('siteRootDir').'/application/Configs/Config.ini')) {
  58. $error = true;
  59. $this->view->config = false;
  60. }
  61.  
  62. // pre validation media directory
  63. if(!is_writable(Zend_Registry::get('siteRootDir').'/data/media')) {
  64. $error = true;
  65. $this->view->media = false;
  66. }
  67.  
  68. // prevalidation cache
  69. if(!is_writable(Zend_Registry::get('siteRootDir').'/data/cache/')) {
  70. $error = true;
  71. $this->view->cache = false;
  72. }
  73.  
  74. $form = self::$installForm->dbForm();
  75.  
  76.  
  77. // if we have post
  78. if ($this->getRequest()->isPost()) {
  79.  
  80. // If form is not valid
  81. if (!$form->isValid($_POST)) {
  82. $this->view->form = $form;
  83. } else {
  84. $values = $form->getValues();
  85.  
  86. // write config
  87. $config = new Zend_Config_Ini(Zend_Registry::get('siteRootDir').'/application/Configs/Database.ini',
  88. null,
  89. array('skipExtends' => true,
  90. 'allowModifications' => true));
  91.  
  92. $config->default->params->host = $values['host'];
  93. $config->default->params->dbname = $values['dbname'];
  94. $config->default->params->username = $values['username'];
  95. $config->default->params->password = $values['password'];
  96.  
  97. $writer = new Zend_Config_Writer_Ini(array('config' => $config,
  98. 'filename' => Zend_Registry::get('siteRootDir').'/application/Configs/Database.ini'));
  99. $writer->write();
  100.  
  101. // create database use native mysql to do this
  102. @$link = mysql_connect($values['host'], $values['username'], $values['password']);
  103.  
  104. if (!$link) {
  105. $this->view->createDbError = true;
  106. $this->view->dbError = $this->view->translate('Error_Database_Connect_Fail');
  107. $this->view->form = $form;
  108.  
  109. } else {
  110. $sql = "CREATE DATABASE `" . $values['dbname'] . "`";
  111. if (!mysql_query($sql, $link)) {
  112. $this->view->createDbError = true;
  113. $this->view->dbError = mysql_error($link);
  114. $this->view->form = $form;
  115. } else {
  116. $db_selected = mysql_select_db($values['dbname'], $link);
  117. if (!$db_selected) {
  118. $this->view->createDbError = true;
  119. $this->view->dbError = mysql_error($link);
  120. $this->view->form = $form;
  121. } else {
  122.  
  123. // import tables
  124. $filename = Zend_Registry::get('siteRootDir').'/data/voodoo.sql';
  125. $sql = file_get_contents($filename, true);
  126.  
  127. $queries = explode(';', $sql);
  128.  
  129. foreach ($queries as $query){
  130. if (strlen(trim($query)) > 0) {
  131. if( !mysql_query($query)) {
  132. $this->view->createDbError = true;
  133. $this->view->dbError = mysql_error($link);
  134. // drop the Db there was an error
  135. //mysql_query("DROP DATABASE `" . $values['dbname'] . "`");
  136. break;
  137. }
  138. }
  139. }
  140.  
  141. if (!$this->view->dbError) {
  142. // set install to 1
  143. $config = new Zend_Config_Ini(Zend_Registry::get('siteRootDir').'/application/Configs/Config.ini',
  144. null,
  145. array('skipExtends' => true,
  146. 'allowModifications' => true));
  147.  
  148. $config->default->installed = 1;
  149.  
  150. $writer = new Zend_Config_Writer_Ini(array('config' => $config,
  151. 'filename' => Zend_Registry::get('siteRootDir').'/application/Configs/Config.ini'));
  152. $writer->write();
  153.  
  154. // redirect to install step 2
  155. $this->_redirect('install/create-admin');
  156. } else {
  157. $this->view->form = $form;
  158. }
  159. }
  160. }
  161. }
  162.  
  163. }
  164. } else {
  165. $this->view->error = $error;
  166.  
  167. if ( !$error){
  168. $this->view->form = $form;
  169. } else {
  170. $this->form = '';
  171. }
  172. }
  173.  
  174.  
  175. }
  176. }
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 09:17