I try to select data from a database, but I'm unable to get it when I have two parameters after the WHERE.
Code that works:
$conn = null;
$host = 'localhost';
$db = 'database';
$user = 'root';
$pwd = 'root';
$auth = 'EP';
$nr = 2007;
try {
$conn = new \PDO('mysql:host='.$host.';dbname='.$db, $user, $pwd);
$stmt = $conn->prepare('SELECT family FROM table WHERE nr = :nr');
$stmt->execute(array('nr' => $nr));
while($row = $stmt->fetch(PDO :: FETCH_ASSOC)) {
echo '<pre>';
print_r($row);
echo '</pre>';
}
}
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
but when I use following select it doesn't work:
SELECT family FROM table WHERE auth = :auth AND nr = :nr
I think it's a problem in the line
$stmt->execute(array('nr' => $nr));
When I do the following I have no result on the screen:
$stmt->execute(array('nr' => $nr, 'auth' => $auth));
Has anybody an idea what I'm doing wrong?