06-06-2016, 08:50 PM
PDO!!
You should use it like this:
Although it should work, I have not tested it.
You should use it like this:
PHP Code: (Select All)
<?php
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
try {
$query = $db->prepare("SELECT * FROM users WHERE username=:user AND password=:password");
$query->execute(['user' => $username, 'password' => $password]);
if($query->rowCount() > 0) {
echo 'Welcome!!';
} else {
echo 'There is no row with the given credentials.';
}
} catch(PDOException $e) {
echo 'Database error: ' . $e->getMessage();
}
Although it should work, I have not tested it.