Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Tworzenie bazy danych przez plik instalacyjny.
Forum PHP.pl > Forum > PHP
luk5e
Witam, plik instalacyjny nie moze utworzyc bazy danych a wszystkie potrzebne dane ktore ustawia sie w pliku settings.php sa podane. Tak wyglada czesc kodu z pliku instalacyjnego i cała instalacja zatrzymuje sie na tym komunikacie "Error creating database"
  1. <?php
  2. require_once(dirname(__FILE__)."/settings.php");
  3. require_once(dirname(__FILE__)."/includes/template_library/lib_templates.php");
  4.  
  5. $error = null;
  6. $database_found=true;
  7. // Check whether the database exists via the database name.
  8.  
  9.  
  10.  
  11. // Check for the settings.
  12. if(!$MySQL['db'] || !$MySQL['server'] || !$MySQL['user']){
  13. $error = 'Your settings do not have all the database information required!';
  14. }else{
  15. // Connect to the database.
  16. $link = mysql_connect($MySQL['server'], $MySQL['user'], $MySQL['pass']);
  17. if (!$link) {
  18. $error = 'Could not connect: ' . mysql_error();
  19. }
  20. }
  21.  
  22. // Check for errors and only continue if there aren't any.
  23. if($error){
  24. die($error);
  25. }
  26.  
  27. // Check that the database doesn't exist already.
  28. $database_found = mysql_select_db($MySQL['db']);
  29. if($database_found){
  30. $error = 'The database specified in your settings is already installed!';
  31. }
  32.  
  33. if($error){
  34. die($error);
  35. }
  36.  
  37.  
  38. // Create the database.
  39. $sql = 'CREATE DATABASE '.$MySQL['db'];
  40. $database_created = mysql_query($sql, $link);
  41. mysql_select_db($MySQL['db']);
  42. if(!$database_created){
  43. $error = 'Error creating database: ' . mysql_error() . "\n";
  44. }
  45.  
  46. if($error){
  47. die($error);
  48. }


plik settings.php

  1. $MySQL['server']='localhost'; //Server
  2. $MySQL['user']='user'; //Username
  3. $MySQL['pass']='hasło'; //Pasword
  4. $MySQL['db']='nazwa_bazy'; //Database that will be created by the install script and used


gdzie Tu jest jakis bład?
ADeM
Jaki błąd podaje? Użytkownik ma uprawnienia do tworzenia bazy?
luk5e
Jedyny bląd ktory sie pokazuje to " Error creating database" ( linia 43) . Użytkownik to root, wiec ma uprawnienia do tworzenia bazy bo recznie w phpmyadminie na koncie roota moge utworzyc baze. A moze cos jeszcze trzeba włączyc dać jakies inne uprawnienia ? Strasznie mnie to meczy wiec prosze o pomoc .

to nikt nie pomoze?
CuteOne
Jeżeli to zadziała to Twój błąd leży w zapytaniu.. po prostu zabrakło ` ` smile.gif

  1. <?php
  2.  
  3. $mysql['base'] = 'moja_faja_baza';
  4. $mysql['host'] = "localhost";
  5. $mysql['user'] = 'root';
  6. $mysql['pass'] = 'haslo';
  7.  
  8. if(!$conn = @mysql_connect($mysql['host'],$mysql['user'],$mysql['pass']))
  9. die("ERROR: Cannot connect to MySQL");
  10.  
  11. if(@mysql_select_db($mysql['base'], $conn))
  12. die("ERROR: Database ".$mysql['base']." already exist");
  13.  
  14. $query = mysql_query("CREATE DATABASE `".$mysql['base']."`") or die(mysql_error());
  15.  
  16. ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.