-
Notifications
You must be signed in to change notification settings - Fork 0
/
datenbank-beispiel.php
33 lines (24 loc) · 1.24 KB
/
datenbank-beispiel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
# Verbindungsaufbau
$pdo = new PDO('mysql:host=localhost;
dbname=Datenbankname',
'DatenbankUser',
'Passwort',
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);
# the first setAttribute() line, which tells PDO to
# disable emulated prepared statements and
# use real prepared statements. This makes sure the statement and
# the values aren't parsed by PHP before sending it to the MySQL server
# (giving a possible attacker no chance to inject malicious SQL).
# Another benefit with using prepared statements is that if you
# execute the same statement many times in the same session it will
# only be parsed and compiled once, giving you some speed gains.
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
# the error mode isn't strictly necessary, but it is advised to add it.
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# um mehr als 65.000 Datenfelder einzufügen, kann der Parameter
# auf `true` gesetzt werden. Aber meines Erachtens leidet dadurch
# die Insert-Geschwindigkeit erheblich.
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
# $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);