diff --git a/Zweites Jahr/unterrichts_projekt/db_connection_data.php b/Zweites Jahr/unterrichts_projekt/inc/db_connection_data.php similarity index 100% rename from Zweites Jahr/unterrichts_projekt/db_connection_data.php rename to Zweites Jahr/unterrichts_projekt/inc/db_connection_data.php diff --git a/Zweites Jahr/unterrichts_projekt/db_connection_function.php b/Zweites Jahr/unterrichts_projekt/inc/db_connection_function.php similarity index 87% rename from Zweites Jahr/unterrichts_projekt/db_connection_function.php rename to Zweites Jahr/unterrichts_projekt/inc/db_connection_function.php index dd52c30..f9ba82e 100644 --- a/Zweites Jahr/unterrichts_projekt/db_connection_function.php +++ b/Zweites Jahr/unterrichts_projekt/inc/db_connection_function.php @@ -10,11 +10,11 @@ function db_connect(){ echo "

DB Connection succesfull established!

"; return $dbh; } catch (PDOException $e){ - echo "Could not connect to DB!
"; + //echo "Could not connect to DB!
"; die("More:".$e->getMessage()); } } // Test: -db_connect(); \ No newline at end of file +// db_connect(); \ No newline at end of file diff --git a/Zweites Jahr/unterrichts_projekt/pdo_test.php b/Zweites Jahr/unterrichts_projekt/pdo_test.php new file mode 100644 index 0000000..46617be --- /dev/null +++ b/Zweites Jahr/unterrichts_projekt/pdo_test.php @@ -0,0 +1,77 @@ + + + + + + PDO >> TEST << + + + exec($addUser); + echo "USER CREATED"; + } catch (PDOException $e) { + $errMsg = $e->getMessage(); + $errCode = $e->getCode(); + //echo "ERROR: user could not created. try again later"; + //echo "
Error Message: $errMsg"; + //echo "
Error-Code: $errCode"; + $custErrMsg = NULL; + + switch ($errCode) { + case "23000": $custErrMsg = "

Email-Adress already exists

"; break; + default: $custErrMsg = "

Oooooops, something went wrong!

"; + } + } + echo $custErrMsg; + + // #################################### + // read records from db + + // wähle * (alles) aus 'user' (tabelle) + $readUser = "SELECT * FROM user"; + + /*speicher das ergebnis in der variable, + // führe den SQL befehl aus und wandle + // das ergebnis in einen array um. + // resultReadUser = $dbh->query($readUser)->fetchAll(); + $dbh->exec($readUser); + + echo "
";
+    print_r($resultReadUser);
+    echo "
"; + */ + + // speicher das ergebnis in der variable, + // führe den SQL befehl aus + $resultReadUser = $dbh->query($readUser); + $dbh->exec($readUser); + + echo "ID | VORNAME | NACHNAME | MAIL
"; + foreach($resultReadUser as $row) { + echo "$row[0] | $row[1] | $row[2] | $row[3]
"; + } + + ?> + + \ No newline at end of file