无法使用PHP和PDO记录用户

From the PDO manual:

PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.

If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.

I have this code:

<?php

require 'core.inc.php';

if(isset($_POST['user']) AND isset($_POST['pass'])){

    if(!empty($_POST['user']) AND !empty($_POST['pass'])){
        $user = $_POST['user'];
        $pass = $_POST['pass'];
            require 'connect.inc.php';
            $st = $db_pdo->prepare("SELECT id FROM users WHERE user=? AND pass=?");
            $st->bindParam(1, $user);
            $st->bindParam(2, $pass);
            $st->execute();
            $result = $st->fetchColumn();
                if($st->rowCount() > 0){
                   $id_arr = $st->fetch();
                   $id = $id_arr[0];
                   $_SESSION['user_id'] = $id;
                   header('Location: edit.php');
                    } else { echo 'Username or password incorrect';}

    } else { echo 'You must fill in all fields.';}
}
?>

The number of rows returned is always 0, as stated in the manual. No surprise there.

1) I want to log a user in and set his $_SESSION id to his user ID from a db.

2) I suck so much at PDO it's not even funny, I can't figure out what function to use to log the user in. If the number or rows is always 0, clearly the Username or password incorrect will appear all the time.

Try this :

try 

 {
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host='.$host.';dbname=' . $dbname, $dbuser, $dbpassword, $pdo_options);

$request = $bdd->prepare('SELECT id FROM users WHERE user = :user AND pass = :password');
$request->execute(array('user' => $_POST['user'],                                               
                        'password' => $_POST['pass']                  
                                                    ));

$data = $request->fetch();

if ($data)
    {
         session_start();
         $_SESSION['ID'] = $data['id'];
         //you can run other verification here if you want
         header('Location: edit.php');

    }
else 
    { 
        echo 'Username or password incorrect';
    }
$requete->closeCursor();

}

catch(Exception $erreur)

   {
      die('Login error : '.$erreur->getMessage());
   }

Hope that helps .