Axel Nordh пре 4 година
родитељ
комит
c66a8ec300

+ 73 - 0
OddsJavaFx/src/web/back/dbFunctions.php

@@ -0,0 +1,73 @@
+<?php
+		use function dbFunctions\checkIfTableExists;
+use function dbFunctions\createBookmakerTable;
+
+class dbFunctions
+{
+
+	private $serverName, $username, $password, $conn, $database;
+
+	public function __construct() {
+		$this->dbFunctions();
+	}
+
+	public function dbFunctions() {
+		$this->serverName = 'nordh.xyz';
+		$this->username = 'odds';
+		$this->password = 'czea_Wm0vK5vaJruM';
+		$this->database = 'new_odds';
+		$this->conn = NULL;
+	}
+
+	// Create Connection
+	function connect() {
+		if ($this->conn == NULL || ! $this->conn->ping()) {
+			$this->conn = new mysqli($this->serverName, $this->username, $this->password, $this->database);
+		}
+
+		// Check connection
+		if ($this->conn->connect_error) {
+			die("Connection failed: " . $this->conn->connect_error);
+		}
+		mysqli_set_charset($this->conn, 'utf8');
+	}
+
+	public function getConnection() {
+		if ($this->conn == NULL || ! $this->conn->ping()) {
+			$this->connect();
+		}
+		return $this->conn;
+	}
+
+	function checkIfTableExists($tableName) {
+		$result = $this->getSqlAsArray("SHOW TABLES LIKE '" . $leagueName . $this->tableName . "'");
+		return ! empty($result);
+	}
+
+	public function close() {
+		$this->conn->close();
+	}
+
+	function getSqlAsArray($sql) {
+		$mysql = $this->getConnection();
+		$result = $mysql->query($sql);
+		if ($result === false) {
+			echo $mysql->error . " from sql " . $sql . PHP_EOL;
+			return null;
+		}
+		$returnArray = array();
+		try {
+			if (is_array($result) || is_object($result)) {
+				foreach ($result as $key => $value) {
+					$returnArray[$key] = $value;
+				}
+			} else {
+				$returnArray[0] = "SUCCESS";
+			}
+		} catch (Exception $e) {
+			echo __FILE__ . " " . $e->getMessage();
+		}
+
+		return $returnArray;
+	}
+}

+ 43 - 0
OddsJavaFx/src/web/back/webDbConnection.php

@@ -0,0 +1,43 @@
+<?php
+mysqli_report( MYSQLI_REPORT_STRICT );
+
+require_once __DIR__ . 'dbFunctions.php';
+
+class WebDbConnection {
+    private $dbCon;
+    private $analyzerConnection;
+    private $today;
+    private $leagueName;
+    public function __construct() {
+        $this->dbCon = new dbFunctions();
+    }
+ 
+    private function getSqlAsArray($sql) {
+        $mysql = $this->dbCon->getConnection();
+        $result = $mysql->query( $sql );
+        if ($result === false) {
+            echo $mysql->error . " from sql " . $sql;
+            return false;
+        }
+        $returnArray = array ();
+        if (strpos( $sql, "UPDATE" ) === false) {
+            foreach ( $result as $key => $value ) {
+                $returnArray [$key] = $value;
+            }
+        }
+        
+        return $returnArray;
+    }
+  
+    private function getCountries() {
+        $mysql = $this->dbCon->getConnection();
+        $sql = "SELECT id, name FROM Country WHERE id IN (SELECT countryId FROM SoccerResults WHERE DATE(gameDate) >= DATE(NOW())) GROUP BY name ORDER BY prio DESC, name ASC";
+
+        $result = $mysql->query( $sql );
+        if ($result === false) {
+            echo $result->error;
+        }
+        
+        return getSqlAsArray($sql);
+    }
+}

+ 13 - 0
OddsJavaFx/src/web/front/index.php

@@ -1,3 +1,11 @@
+<?php 
+include_once __DIR__ . '../back/webDbConnection.php';
+
+$conn = new WebDbConnection( );
+
+$leagues = $conn->getCountries();
+?>
+
 <head>
   <link rel="stylesheet" href="style.css">
 </head>
@@ -5,6 +13,11 @@
 <body>
 <H2>Odds</H2>
 
+<label for="countrySelector">Select country: </label>
+
+
+
+<button></button>
 
 
     <table id="matchTable" hidden>