Completed
Push — master ( 597a61...2224b9 )
by Yannick
25:05
created
install/class.create_db.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -8,24 +8,24 @@  discard block
 block discarded – undo
8 8
 	 * @param string $filename
9 9
 	 */
10 10
 	public static function import_file($filename) {
11
-		$filename = filter_var($filename,FILTER_SANITIZE_STRING);
11
+		$filename = filter_var($filename, FILTER_SANITIZE_STRING);
12 12
 		$Connection = new Connection();
13 13
 		//Connection::$db->beginTransaction();
14 14
 		$templine = '';
15
-		$handle = @fopen($filename,"r");
15
+		$handle = @fopen($filename, "r");
16 16
 		if ($handle) {
17 17
 			//$lines = file($filename);
18 18
 			//foreach ($lines as $line)
19
-			while (($line = fgets($handle,4096)) !== false)
19
+			while (($line = fgets($handle, 4096)) !== false)
20 20
 			{
21
-				if (substr($line,0,2) == '--' || $line == '') continue;
21
+				if (substr($line, 0, 2) == '--' || $line == '') continue;
22 22
 				$templine .= $line;
23
-				if (substr(trim($line), -1,1) == ';')
23
+				if (substr(trim($line), -1, 1) == ';')
24 24
 				{
25 25
 					try {
26 26
 						$sth = $Connection->db->prepare($templine);
27 27
 						$sth->execute();
28
-					} catch(PDOException $e) {
28
+					} catch (PDOException $e) {
29 29
 						return "error (import ".$filename.") : ".$e->getMessage()."\n";
30 30
 					}
31 31
 					$templine = '';
@@ -42,27 +42,27 @@  discard block
 block discarded – undo
42 42
 		$error = '';
43 43
 		$dh = opendir($directory);
44 44
 		//foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $filename)
45
-		while(false !== ($filename = readdir($dh)))
45
+		while (false !== ($filename = readdir($dh)))
46 46
 		{
47
-			if (preg_match('/\.sql$/',$filename)) $error .= create_db::import_file($directory.$filename);
47
+			if (preg_match('/\.sql$/', $filename)) $error .= create_db::import_file($directory.$filename);
48 48
 		}
49 49
 		return $error;
50 50
 	}
51 51
 
52
-	public static function create_database($root,$root_pass,$user,$pass,$db,$db_type,$host) {
53
-		$root = filter_var($root,FILTER_SANITIZE_STRING);
54
-		$root_pass = filter_var($root_pass,FILTER_SANITIZE_STRING);
55
-		$user = filter_var($user,FILTER_SANITIZE_STRING);
56
-		$password = filter_var($pass,FILTER_SANITIZE_STRING);
57
-		$db = filter_var($db,FILTER_SANITIZE_STRING);
58
-		$db_type = filter_var($db_type,FILTER_SANITIZE_STRING);
59
-		$host = filter_var($host,FILTER_SANITIZE_STRING);
52
+	public static function create_database($root, $root_pass, $user, $pass, $db, $db_type, $host) {
53
+		$root = filter_var($root, FILTER_SANITIZE_STRING);
54
+		$root_pass = filter_var($root_pass, FILTER_SANITIZE_STRING);
55
+		$user = filter_var($user, FILTER_SANITIZE_STRING);
56
+		$password = filter_var($pass, FILTER_SANITIZE_STRING);
57
+		$db = filter_var($db, FILTER_SANITIZE_STRING);
58
+		$db_type = filter_var($db_type, FILTER_SANITIZE_STRING);
59
+		$host = filter_var($host, FILTER_SANITIZE_STRING);
60 60
 		// Dirty hack
61 61
 		if ($host != 'localhost' && $host != '127.0.0.1') {
62 62
 			$grantright = $_SERVER['SERVER_ADDR'];
63 63
 		} else $grantright = 'localhost';
64 64
 		try {
65
-			$dbh = new PDO($db_type.':host='.$host,$root,$root_pass);
65
+			$dbh = new PDO($db_type.':host='.$host, $root, $root_pass);
66 66
 			$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
67 67
 			if ($db_type == 'mysql') {
68 68
 				$dbh->exec('CREATE DATABASE IF NOT EXISTS `'.$db.'`;GRANT ALL ON `'.$db."`.* TO '".$user."'@'".$grantright."' IDENTIFIED BY '".$password."';FLUSH PRIVILEGES;");
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 				$dbh->exec("CREATE USER ".$user." WITH PASSWORD '".$password."';
73 73
 					GRANT ALL PRIVILEGES ON DATABASE ".$db." TO ".$user.";");
74 74
 			}
75
-		} catch(PDOException $e) {
75
+		} catch (PDOException $e) {
76 76
 			$dbh = null;
77 77
 			return "error : ".$e->getMessage();
78 78
 		}
Please login to merge, or discard this patch.