emailconfirmed, nsInternRO, nsInternRW, Administrators
3,356
edits
m (→2. Das Backend) |
mNo edit summary |
||
Line 4: | Line 4: | ||
Für das folgende schnelle Praxis-Beispiel brauchen wir lediglich entsprechende Rechte, um eine neue Datenbank anlegen zu können und Zugriff auf den SQL-Server sowie einen Benutzernamen und Passwort (bei XAMP ist das Standardmäßig "localhost" sowie "root/root". | Für das folgende schnelle Praxis-Beispiel brauchen wir lediglich entsprechende Rechte, um eine neue Datenbank anlegen zu können und Zugriff auf den SQL-Server sowie einen Benutzernamen und Passwort (bei XAMP ist das Standardmäßig "localhost" sowie "root/root". | ||
Ein schnelles Beispiel aus der Praxis, wie SQL mit PHP zu benutzen ist. | Ein schnelles Beispiel aus der Praxis, wie SQL mit PHP zu benutzen ist. | ||
== | == Database Connection == | ||
Jedes mal wenn auf die Datenbank zugegriffen werden soll, muss eine Verbindung aufgebaut werden, für die wir die Verbindungsdaten benötigen. Deshalb wird hier eine kurze PHP-Datei angelegt, die wir in alle weiteren PHP-Skripte einfach inkludieren können. Es ist hier besonders darauf zu achten, dass diese Datei niemals mit einer anderen Endung als .php oder .php5 am Server liegen sollte, damit diese Daten von niemandem ausgelesen werden können. Eine weitere übliche Vorgehensweise ist, diese Datei außerhalb des Webserver-Wurzelverzeichnisses abzulegen (auf das kein normaler Websurfer Zugriff haben sollte) | Jedes mal wenn auf die Datenbank zugegriffen werden soll, muss eine Verbindung aufgebaut werden, für die wir die Verbindungsdaten benötigen. Deshalb wird hier eine kurze PHP-Datei angelegt, die wir in alle weiteren PHP-Skripte einfach inkludieren können. Es ist hier besonders darauf zu achten, dass diese Datei niemals mit einer anderen Endung als .php oder .php5 am Server liegen sollte, damit diese Daten von niemandem ausgelesen werden können. Eine weitere übliche Vorgehensweise ist, diese Datei außerhalb des Webserver-Wurzelverzeichnisses abzulegen (auf das kein normaler Websurfer Zugriff haben sollte) | ||
Line 27: | Line 26: | ||
</source> | </source> | ||
== | == Das Backend == | ||
In diesem Beispiel gehen wir von einer einfachen Datenbankstruktur aus. Wir haben Produkte, und diese Produkte haben alle einen Titel und einen Preis. | In diesem Beispiel gehen wir von einer einfachen Datenbankstruktur aus. Wir haben Produkte, und diese Produkte haben alle einen Titel und einen Preis. | ||
Es gibt nun zwei PHP-Skripte. Das eine ist das "Frontend", hier wird die Datenbank ausgelesen und alle vorhandenen Produkte in einer Tabelle angezeigt (siehe unten). Das zweite Script ist das Backend, in dem wir die einzelnen Einträge bearbeiten können - außerdem wird hier die Tabelle und die Datenbank angelegt, wenn sie nicht schon vorhanden ist. | Es gibt nun zwei PHP-Skripte. Das eine ist das "Frontend", hier wird die Datenbank ausgelesen und alle vorhandenen Produkte in einer Tabelle angezeigt (siehe unten). Das zweite Script ist das Backend, in dem wir die einzelnen Einträge bearbeiten können - außerdem wird hier die Tabelle und die Datenbank angelegt, wenn sie nicht schon vorhanden ist. | ||
Somit sind die Aufgaben des Backends: | |||
* Database Server Connect (siehe oben) | |||
* Create Database if not exist | |||
* Create Tables in Database if not exist | |||
* Add some values | |||
* Show Table Contents in From | |||
* Update Values in Database | |||
''Datei backend.php:'' | ''Datei backend.php:'' | ||
Line 128: | Line 136: | ||
=== 3. Das Frontend === | === 3. Das Frontend === | ||
...ist im Prinzip das Gleiche wie das Backend, nur sehr viel einfacher, da wir uns nicht darum kümmern müssen, die Werte zu aktualisieren. Außerdem kann man davon ausgehen, dass alle Tabellen und die Datenbank bereits exisitieren | ...ist im Prinzip das Gleiche wie das Backend, nur sehr viel einfacher, da wir uns nicht darum kümmern müssen, die Werte zu aktualisieren. Außerdem kann man davon ausgehen, dass alle Tabellen und die Datenbank bereits exisitieren. | ||
Somit sind die Aufgaben des Frontends: | |||
* Database Server Connect (siehe oben) | |||
* Show Table Contents (siehe oben) | |||
''Datei frontend.php:'' | ''Datei frontend.php:'' |