I'm getting problems with my PDO query as soon as there is an apostrophe inside the name I'm looking for, like D'Angelo. Names without (') inside the name are working fine.
try {
$dbh = new PDO("mysql:host=$host;dbname=$dbname",$config['DB_USERNAME'],$config['DB_PASSWORD']);
foreach($dbh->query("SELECT * from position WHERE spieler='$playername'") as $row) {
echo ''.$row['pos'].'</td></tr>';
}
$dbh = null;
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Update:
So, with all the help and hints to prepared statements I was able to get this finally to work.
$dbh = new PDO("mysql:host=$host;dbname=$dbname",$config['DB_USERNAME'],$config['DB_PASSWORD']);
$stmt = $dbh->prepare("SELECT * from position WHERE spieler=:player1");
$stmt->execute(array(":player1" => $player1));
foreach ($stmt as $row) {
echo ''.$row['pos'].'</td></tr>';
}
$dbh = null;