PHP
Der Verbinder
Kursdateien
- PHPMailer-master.zip (134,40 KiB / 30.06.2023 14:32:56)
- grundlagen.zip (183,06 KiB / 20.06.2024 10:23:04)
- oop.zip (19,08 KiB / 04.02.2025 10:38:58)
- php.zip (465,24 KiB / 04.02.2025 10:38:42)
Liste der Erweiterungen
HTML
-
HTML Extension Pack von JAderBass
Extension Pack für die JAderBass web'n'more HTML/CSS-Kurse
In diesem Extension Pack sind enthalten:
- Auto Close Tag von Jun Han Bewirkt, dass bei der Eingabe eines Tags das dazugehörige schließende Tag gleich mit angegeben wird
- Autoprefixer von mrmlnc Fügt automatisch die eingestellten Vendor-Prefixe für CSS-Regeln hinzu
- Better Comments von Aaron Bond Macht verschiedenfarbige Kommentare möglich
-
HTML CSS Support von ecmel
Bewirkt HTML-
classund -idAttribut-Vervollständigung - HTML End Tag Labels von Ante Primorac Blendet an End-Tags die ID- und Klassenbezeichnungen ein, um den Code übersichtlicher zu gestalten
PHP
- PHP Intelephense von Ben Mewburn Debug Support mit Xdebug
Hinweis
PHP ist eine serverbasierte Skriptsprache. Um mit PHP entwickeln zu können benötigen wir einen Webserver. Welchen Webserver wir benutzen ist im Grunde egal. Hauptsache ist, dass PHP auf diesem Webserver installiert ist.
Bisher habe ich, um lokal wie mit einem "echten" Webserver arbeiten zu können XAMPP benutzt. Ein Packet, welches einen komplett aufgesetzten Apache-Webserver mit PHP- und MariaDB-Unterstützung etc. beinhaltet. Leider ist es momentan so, dass die letzte PHP-Version, welche XAMPP unterstützt, nicht mehr aktiv supportet wird.
Aus diesem Grund nutze ich jetzt Laragon. Dieses Paket beinhaltet ebenfalls alle wichtigen Tools (u.a. PHP und einen MariaDB-Server) um lokal einen funktionierenden Webserver (Apache) für die Arbeit als Webentwickler durchführen zu können. Das Paket kann unter https://laragon.org/download/ heruntergeladen und installiert werden.
PHP Executable Path einstellen
- über
STRG + ,die Settings öffnen - oben rechts auf das kleine Datei-Icon klicken

- es öffnet sich die Datei
settings.json -
der Eintrag
"php.validate.executablePath": ""wird ans Ende der Dateisettings.jsongeschrieben. Diesen Eintrag mit dem Pfad der PHP-Erweiterung ergänzen.
solltest Du noch XAMPP mit der Standard-Installation nutzen, sieht der komplette Eintrag folgendermaßen aus:Wenn Du Laragon mit der Standard-Installation nutzt, nimmst Du folgenden Eintrag:"php.validate.executablePath": "c:/xampp/php/php.exe""php.validate.executablePath": "c:/laragon/bin/php.exe"
Eigene Code-Snippets nutzen
Ich habe für meine Kurse eigene Code-Snippet-Dateien erstellt, die das Coding erheblich erleichtern. Mit den folgenden Schritten kannst du diese Snippets selbst nutzen:
- Snippets-Verzeichnis öffnen:
-
Windows:
%APPDATA%\Code\User\snippets -
Mac:
~/Library/Application Support/Code/User/snippets/ -
Linux:
$HOME/.config/Code/User/snippets/
-
Windows:
- Variante 1 (empfohlen):
- Die Datei(en)
jdb-html.code-snippetsundjdb-php.code-snippetshier herunterladen und in dieses Verzeichnis kopieren. - Sollte bereits eine Datei
jdb-html.code-snippetsbzw.jdb-php.code-snippetsexistieren: diese ersetzen oder:
- Die Datei(en)
- Variante 2:
- Die Datei(en) in einem Editor öffnen, bzw.
- eine Text-Datei anlegen und unter dem Namen
jdb-html.code-snippetsbzw.jdb-php.code-snippetsim oben genannten Verzeichnis speichern und - unten stehenden Code in die neue(n) Datei(en) kopieren, bzw. die bestehende(n) Datei(en) nach dem unten stehenden Muster ändern oder:
- Variante 3:
- Im VSCode unter Datei > Einstellungen > Benutzercodeschnipsel konfigurieren (Windows) bzw. Code > Einstellungen > Benutzercodeschnipsel konfigurieren (Mac) eine "Neue globale Codeschnipseldatei..." erstellen und diese z.B.
jdb-html.code-snippetsbzw.jdb-php.code-snippetsbenennen. - Den unten stehenden Code in diese Datei kopieren und speichern.
- Im VSCode unter Datei > Einstellungen > Benutzercodeschnipsel konfigurieren (Windows) bzw. Code > Einstellungen > Benutzercodeschnipsel konfigurieren (Mac) eine "Neue globale Codeschnipseldatei..." erstellen und diese z.B.
Snippets für PHP
{
// HTML
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Kommentar Titel HTML": {
"scope": "html",
"prefix": "komtitel",
"body": [
"<!-- ${1:Titel}",
"============================================================================================= -->"
],
"description": "Ausgabe eines Kommentar-Titels in HTML-Dateien"
},
"Kommentar Titel CSS/SCSS": {
"scope": "css,scss",
"prefix": "komtitel",
"body": "/* === ${1:Titel} === */",
"description": "Ausgabe eines Kommentar-Titels in CSS-Dateien"
},
"Bootstrap 5 Grundgerüst nur CSS": {
"scope": "html,php,blade",
"prefix": "bs5",
"description": "Bootstrap Grundgerüst nur CSS",
"body": [
"<!DOCTYPE html>",
"<html lang=\"de\">",
"<head>",
"\t<meta charset=\"UTF-8\">",
"\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">",
"\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
"\t<title>${1:Document}</title>",
"\t<!-- CSS only -->",
"\t<!-- Bootstrap-CSS -->",
"\t<link rel=\"stylesheet\" href=\"css/bootstrap.min.css\">",
"\t<!-- Custom-CSS -->",
"\t<link rel=\"stylesheet\" href=\"$2\">",
"</head>",
"<body>",
"\t$3",
"</body>",
"</html>"
]
},
"Bootstrap 5 Grundgerüst mit JS": {
"scope": "html,php,blade",
"prefix": "bs5js",
"description": "Bootstrap Grundgerüst - komplett mit JavaScript",
"body": [
"<!DOCTYPE html>",
"<html lang=\"de\">",
"<head>",
"\t<meta charset=\"UTF-8\">",
"\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">",
"\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
"\t<title>${1:Document}</title>",
"\t<!-- CSS only -->",
"\t<!-- Bootstrap-CSS -->",
"\t<link rel=\"stylesheet\" href=\"css/bootstrap.min.css\">",
"\t<!-- Custom-CSS -->",
"\t<link rel=\"stylesheet\" href=\"$2\">",
"</head>",
"<body>",
"\t$3",
"<!-- Bootstrap JavaScript -->",
"<script src=\"js/bootstrap.bundle.min.js\"></script>",
"</body>",
"</html>"
]
},
"Bootstrap JS": {
"scope": "html,php,blade",
"prefix": "bs5jsonly",
"description": "Bootstrap JavaScript",
"body": [
"<!-- Bootstrap JavaScript -->",
"<script src=\"js/bootstrap.bundle.min.js\"></script>"
]
}
}
{
// PHP
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Schreibe Header": {
"scope": "php",
"prefix": "phead",
"body": [
"require_once( '../includes/functions.inc.php' );",
"/*",
"* get_header(",
"*\tstring \\$title,",
"*\tstring/array \\$css=NULL,",
"*\tbool \\$bootstrap=false,",
"*\tstring \\$header=NULL,",
"*\tarray \\$nav=NULL,",
"*\tbool \\$fluid=false",
"* )",
"*/",
"\\$args = array(",
"\t$1",
");",
"get_header( ...\\$args );",
"?>"
],
"description": "Fügt das Script für die Einbindung des HTML-Headers ein"
},
"Schreibe Footer": {
"scope": "php",
"prefix": "pfoot",
"body": "<?php get_footer(); ?>",
"description": "Fügt das Script für die Einbindung des HTML-Footers ein"
},
"PHP-Bereich": {
"scope": "html",
"prefix": "php",
"body": "<?php $0 ?>",
"description": "Fügt einen PHP-Bereich ein."
},
"PHP-Ausgabe": {
"scope": "html",
"prefix": "pecho",
"body": "<?= $0 ?>",
"description": "Fügt eine PHP-Ausgabe ein."
},
"PHP-Bereich Umbruch": {
"scope": "html",
"prefix": "php+",
"body": [
"<?php",
"\t",
"\t$0",
"\t",
"?>"
],
"description": "Fügt einen PHP-Bereich mit Zeilenumbrüchen ein."
},
"Formular Eigenaufruf": {
"scope": "php,html",
"prefix": "formself",
"body": [
"<form action=\"<?= \\$_SERVER['SCRIPT_NAME']; ?>\" method=\"post\">",
"\t$0",
"</form>"
],
"description": "Fügt einen Formular-Bereich mit Selbstaufruf ein."
},
"Grundgerüst für PHP": {
"scope": "php,html",
"prefix": "pfull",
"body": [
"<?php",
"require_once( '../includes/functions.inc.php' );",
"/* get_header(",
"*\tstring \\$title,",
"*\tstring/array \\$css=NULL,",
"*\tbool \\$bootstrap=false,",
"*\tstring \\$header=NULL,",
"*\tarray \\$nav=NULL,",
"*\tbool \\$fluid=false",
"* )",
"*/",
"\\$args = array(",
"\t$1",
");",
"get_header( ...\\$args );",
"?>",
"\t$2",
"<?php get_footer(); ?>"
],
"description": "Fügt das Grundgerüst für den PHP-Kurs ein."
},
"Grundgerüst PHP mit DB": {
"scope": "php,html",
"prefix": "pfulldb",
"body": [
"<?php",
"require_once( '../includes/functions.inc.php' );",
"\\$database = $1;",
"/* get_header(",
"*\tstring \\$title,",
"*\tstring/array \\$css=NULL,",
"*\tbool \\$bootstrap=false,",
"*\tstring \\$header=NULL,",
"*\tarray \\$nav=NULL,",
"*\tbool \\$fluid=false",
"* )",
"*/",
"\\$args = array(",
"\t$2",
");",
"get_header( ...\\$args );",
"require_once( '../includes/pdo-connect.inc.php' );",
"?>",
"\t$3",
"<?php get_footer(); ?>"
],
"description": "Fügt das Grundgerüst für den PHP-Kurs inklusive Datenbankzugriff ein."
},
"var_dump()": {
"scope": "php",
"prefix": "vd",
"body": "echo '<pre>', var_dump( $1 ), '</pre>';",
"description": "Gibt ein pre-formatiertes var_dump() aus."
},
"var_dump()+": {
"scope": "php",
"prefix": "vd+",
"body": [
"echo '<pre>';",
"var_dump( $1 )",
"echo '</pre>';"
],
"description": "Gibt ein pre-formatiertes var_dump() mit Zeilenumbrüchen aus."
},
"print_r()": {
"scope": "php",
"prefix": "pr",
"body": "echo '<pre>', print_r( $1 ), '</pre>';",
"description": "Gibt ein pre-formatiertes print_r() aus."
},
"print_r()+": {
"scope": "php",
"prefix": "pr+",
"body": [
"echo '<pre>'",
"print_r( $1 )",
"echo '</pre>';"
],
"description": "Gibt ein pre-formatiertes print_r() mit Zeilenumbrüchen aus."
},
"Absatzausgabe PHP": {
"scope": "php",
"prefix": "ep",
"body": "echo '<p>' . $1 . '</p>';",
"description": "Gibt per echo je ein Absatz-Anfangs und Ende-Tag aus und setzt den Zeiger in die Zeile dazwischen."
},
"Absatzausgabe PHP mit Umbruch": {
"scope": "php",
"prefix": "ep+",
"body": [
"echo '<p>';",
"$1",
"echo '</p>';"
],
"description": "Gibt per echo je ein Absatz-Anfangs und Ende-Tag aus und setzt den Zeiger in die Zeile dazwischen."
},
"Kommentar Titel PHP": {
"scope": "php",
"prefix": "komtitel",
"body": [
"/* === ${1:Titel}",
"============================================================================================= */"
],
"description": "Ausgabe eines Kommentar-Titels in PHP-Dateien"
},
"ausführlicher Kommentar": {
"scope": "php",
"prefix": "komfull",
"body": [
"/**",
" * ${1:Summary}",
" *",
" * ${2:Description}",
" *",
" * @author ${3}",
" *",
" * @since ${4:x.x.x}",
" *",
" * @see ${5:function/method/class} relied on",
" * @link ${6:url}",
" * @global ${7:type} ${8:varname} ${9:Description}.",
" * @param ${10:type} ${11:var} ${12:Optional. / Description. / Default.}",
" * @return ${13:type} ${14:Description}.",
" */"
],
"description": "Ausgabe eines ausführlichen Kommentar-Textes zur Beschreibung von Funktionen / Methoden / Klassen in PHP-Dateien"
},
"PHP SQL-Abfrage": {
"scope": "php",
"prefix": "sqlquery",
"body": [
"\\$sql = $1;",
"",
"\\$result = mysqli_query( \\$db, \\$sql );",
"",
"if( false === \\$result ) {",
"\t$2",
"} else {",
"\techo get_db_error( \\$db, \\$sql );",
"}"
],
"description": "MySQLi Abfrage + Auswertung"
},
"PHP PDO-SELECT-Abfrage": {
"scope": "php",
"prefix": "pdoselect",
"body": [
"\\$sql = '$1';",
"",
"try {",
"\tif (\\$stmt = \\$pdo->query(\\$sql)) {",
"\t\tif( \\$stmt->rowCount() === 0 ) {",
"\t\t\techo '<p>Keine Datensätze gefunden.</p>';",
"\t\t} else {",
"\t\t\twhile (\\$row = \\$stmt->fetch(PDO::FETCH_OBJ)) {",
"\t\t\t\t$2",
"\t\t\t}",
"\t\t}",
"\t}",
"} catch (PDOException \\$e) {",
"\techo get_db_error(\\$pdo, \\$sql, \\$e);",
"}",
"\\$stmt = NULL;",
"\\$pdo = NULL;"
],
"description": "PDO SELECT"
},
"PHP PDO-SELECT-Prepared": {
"scope": "php",
"prefix": "ppselect",
"body": [
"\\$sql = 'SELECT $1 FROM $2';",
"",
"try {",
"\tif (\\$stmt = \\$pdo->prepare(\\$sql)) {",
"\t\t\\$stmt->bindParam( $3, $4);",
"\t\t\\$stmt->execute();",
"\t\tif( \\$stmt->rowCount() === 0 ) {",
"\t\t\techo '<p>Keine Datensätze gefunden.</p>';",
"\t\t} else {",
"\t\t\twhile (\\$row = \\$stmt->fetch(PDO::FETCH_ASSOC)) {",
"\t\t\t\t$5",
"\t\t\t}",
"\t\t}",
"\t}",
"} catch (PDOException \\$e) {",
"\techo get_db_error(\\$pdo, \\$sql, \\$e);",
"}",
"\\$stmt = NULL;",
"\\$pdo = NULL;"
],
"description": "PDO SELECT mit Prepared Statements"
},
"PHP PDO-INSERT-Prepared": {
"scope": "php",
"prefix": "ppinsert",
"body": [
"if(!empty(\\$_POST)) {",
"\t\\$sql = 'INSERT INTO $1",
"\t(",
"\t\t$2",
"\t)",
"\tVALUES",
"\t(",
"\t\t$3",
"\t)';",
"\t",
"\ttry {",
"\t\tif (\\$stmt = \\$pdo->prepare(\\$sql)) {",
"\t\t\t\\$stmt->bindParam( $4, $5);",
"",
"\t\t\tif( \\$stmt->execute() ) {",
"\t\t\t\techo '<p>Der Datensatz wurde angelegt</p>';",
"\t\t\t}",
"\t\t}",
"\t} catch (PDOException \\$e) {",
"\t\techo get_db_error(\\$pdo, \\$sql, \\$e);",
"\t}",
"}",
"\t\\$stmt = NULL;",
"\t\\$pdo = NULL;"
],
"description": "PDO INSERT mit Prepared Statements"
},
"PHP PDO-UPDATE-Prepared": {
"scope": "php",
"prefix": "ppupdate",
"body": [
"if(!empty(\\$_POST)) {",
"\t\\$sql = 'UPDATE $1",
"\tSET $2",
"\tWHERE $3';",
"\t",
"\ttry {",
"\t\tif (\\$stmt = \\$pdo->prepare(\\$sql)) {",
"\t\t\t\\$stmt->bindParam( $4, $5);",
"",
"\t\t\tif( \\$stmt->execute() ) {",
"\t\t\t\techo '<p>Es wurden ' . \\$stmt->rowCount() . ' Datensätze geändert.</p>';",
"\t\t\t}",
"\t\t}",
"\t} catch (PDOException \\$e) {",
"\t\techo get_db_error(\\$pdo, \\$sql, \\$e);",
"\t}",
"}",
"\t\\$stmt = NULL;",
"\t\\$pdo = NULL;"
],
"description": "PDO UPDATE mit Prepared Statements"
},
"PHP PDO-DELETE-Prepared": {
"scope": "php",
"prefix": "ppdel",
"body": [
"if(!empty(\\$_POST)) {",
"\t\\$sql = 'DELETE $1 FROM $2",
"\tWHERE $3';",
"\t",
"\ttry {",
"\t\tif (\\$stmt = \\$pdo->prepare(\\$sql)) {",
"\t\t\t\\$stmt->bindParam( $4, $5);",
"",
"\t\t\tif( \\$stmt->execute() ) {",
"\t\t\t\techo '<p>Es wurden ' . \\$stmt->rowCount() . ' Datensätze gelöscht.</p>';",
"\t\t\t}",
"\t\t}",
"\t} catch (PDOException \\$e) {",
"\t\techo get_db_error(\\$pdo, \\$sql, \\$e);",
"\t}",
"}",
"\t\\$stmt = NULL;",
"\t\\$pdo = NULL;"
],
"description": "PDO DELETE mit Prepared Statements"
},
"PHP PDO-Exception handling": {
"scope": "php",
"prefix": "pdoerr",
"body": "echo get_db_error(\\$pdo, \\$sql, \\$e);",
"description": "PDO Ausnahmebehandlung formatiert ausgeben"
}
}