setup.php 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. function RunFile($file){
  3. }
  4. $settings=parse_ini_file("settings.ini",true);
  5. $host=$settings["database"]["host"];
  6. $db=$settings["database"][ "database"];
  7. $username=$settings["database"][ "username"];
  8. $password=$settings["database"][ "password"];
  9. $PDO=new PDO("mysql:host=$host;dbname=$db",$username,$password);
  10. $version=0;
  11. if (file_exists("db_version_info"))
  12. $version=intval(file_get_contents("db_version_info"));
  13. $scriptsToRun=array();
  14. $items=glob("DB Scripts/*.sql");
  15. $scriptsToRun[0]=$items;
  16. $items=glob("DB Scripts/*");
  17. foreach ($items as $i){
  18. if (!is_dir($i))
  19. continue;
  20. $moreItems=glob($i.'/*');
  21. if (count($moreItems)>0)
  22. $scriptsToRun[intval(pathinfo($i)['basename'])]=$moreItems;
  23. }
  24. $total=count($scriptsToRun);
  25. $dbVersion=0;
  26. for ($v=$version;$v<$total;$v++){
  27. foreach ($scriptsToRun[$v] as $s){
  28. echo "Running $s";
  29. $PDO->query(file_get_contents($s));
  30. var_dump($PDO->errorInfo());
  31. }
  32. }
  33. file_put_contents("db_version_info", $total);