I have just uploaded my local project to server but PDO queries are not working in LIVE server. It's working fine on local. I thought PDO might not be installed on server so i ran the below script
PHP version in server is PHP Version 5.3.3
, Linux server
<?php
if (!defined('PDO::ATTR_DRIVER_NAME')) {
echo 'PDO unavailable';
}else{
echo 'pdo is installed';
}
?>
Connection.php:
<?php
try{
$pdo = new PDO('mysql: host=localhost; dbname12', 'myusername', 'password');
}catch(PDOException $e){
exit('Database Error');
}
?>
Login:
<?php
session_start();
include_once('../includes/connection.php');
if(isset($_POST['user_name'], $_POST['user_password'])){
$username = $_POST['user_name'];
$password = md5($_POST['user_password']);
if(empty($username) or empty($password)){
$error = 'All fields are required!';
}else {
$query = $pdo->prepare("SELECT * FROM users WHERE user_name = ? AND user_password = ?");
$query->bindValue(1, $username);
$query->bindValue(2, $password);
$query->execute();
//var_dump($query);exit;
$num = $query->rowCount();
if ($num == 1) {
// User correct details let's log him in
$_SESSION['logged_in'] = true;
header('Location: dashboard.php');
exit();
} else {
$error = 'Incorrect Details';
}
}
}
?>
By entering correct credentials the login is showing incorrect details always
+ For debugging i bypassed the login and entered dashboard where we are fetching articles from DB but nothing was there. And in database we have many entries.