Skip to content

Instantly share code, notes, and snippets.

View cpt-wayfinder's full-sized avatar

cpt-wayfinder

View GitHub Profile
@cpt-wayfinder
cpt-wayfinder / XxxRepository.php
Last active January 2, 2019 09:22
Klasse für Datenbankabfragen #Mysql #pdo #Class
<?php
namespace Whatever\Whatever
use PDO;
class XxxRepository
{
private $pdo;
public function __construct(PDO $pdo)
{
@cpt-wayfinder
cpt-wayfinder / autoloader.php
Created January 2, 2019 07:56
PSR4 Autoloader #Autoloader
<?php
/**
* An example of a project-specific implementation.
*
* After registering this autoload function with SPL, the following line
* would cause the function to attempt to load the \Foo\Bar\Baz\Qux class
* from /path/to/project/src/Baz/Qux.php:
*
* new \Foo\Bar\Baz\Qux;
*
@cpt-wayfinder
cpt-wayfinder / database.php
Created December 31, 2018 00:01
PDO Datenbank Abrufen #Datenbank #Mysql #PDO
<?php
function something($title){
global $pdo;
$stmt=$pdo->prepare("SELECT * FROM 'spaltenname' WHERE title=:title");
$stmt->execute(['title'=>$title]);
return $stmt->fetch();
}
?>
@cpt-wayfinder
cpt-wayfinder / database.php
Last active January 2, 2019 11:56
PDO Verbindung #Datenbank #Mysql #PDO
<?php
$dsn = 'mysql:dbname=lernschlau;host=localhost';
$user = 'root';
$password = 'root';
try {
$dbh = new PDO($dsn, $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Verbindung fehlgeschlagen: ' . $e->getMessage();
@cpt-wayfinder
cpt-wayfinder / autoload.php
Last active January 2, 2019 07:42
Autoload für require #Autoload #include #require
<?php
function autoload($className)
{
$className = str_replace("\\","/",$className);
if (file_exist("./scr/{$className}.php")){
require "./scr/{$className}.php";
}
}
spl_autoload_register("autoload");
?>
@cpt-wayfinder
cpt-wayfinder / emailforumular-erstellen.php
Last active December 28, 2018 11:38
Email Formular erstellen (Funktion) #Email #formular #erstellen
function formular_erstellen ($emailadresse = "",
$gender="",
$vorname="",
$nachname="",
$einverstanden="" )
{
echo '<form name="" action="';
echo $_SERVER['PHP_SELF'];
echo '" method="GET" enctype="text/html">';
@cpt-wayfinder
cpt-wayfinder / emailtext.php
Created December 28, 2018 07:32
Mailtext mit HTML #Mailtext #Email #Mail
<?php
$mailtext='<html>
<head>
<titel>Titel der E-Mail</titel>
</head>
<body>
<h1> Diese E-Mail wurde mit php erstellt</h1>
<p>Text der E-Mail</p>
</html>
?>
@cpt-wayfinder
cpt-wayfinder / mysql.php
Created December 28, 2018 07:22
MySQL Datenverbindung aufbauen / verbinden #MySql #Datenbank #Verbindung
<?php
DEFINE('DB_USERNAME', 'root');
DEFINE('DB_PASSWORD', 'root');
DEFINE('DB_HOST', 'localhost');
DEFINE('DB_DATABASE', 'performance_schema');
$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
if (mysqli_connect_error()) {
die('Connect Error ('.mysqli_connect_errno().') '.mysqli_connect_error());
@cpt-wayfinder
cpt-wayfinder / email-versenden.php
Created December 28, 2018 07:20
Email versnden PHP #email #kontakt
<?php
$empfaenger ="du@domain.de";
$absender = "ich@domain.de";
$betreff ="PHP- Testmail";
$mailtest ="Inhalt der E-Mail";
$antwortan ="ich@domain.de";
mail($empfanger,$betreff,$mailtext,"From: $absender\nReply-To.: $antwortan");
echo "Mail wurde gesendet!";
?>