Jump to content

rowCount


cabbie

Recommended Posts

$count prints out 0  it is retrieving correct username and password from database.  Ideas?

 

<?php
include_once ('connection.php');


class User{
        private $db;
        public function __construct(){        
            $this->db = new Connection();
            $this->db = $this->db->dbConnect();
        }
    
        public function Login($username, $password)
        {
            if(!empty($username) && !empty($password)){
                $st = $this->db->prepare("select * from users where username=? and password=?");
                $st->bindParam(1, $username);
                $st->bindParam(2, $password);
                $st->execute();
 
                    $count = $st->rowCount(); Print $count;  echo $username, ' ', $password;
                if($st->rowCount() == 1){
                    echo "User verified. Access granted";
                }else{
                    echo "Incorrect username or password";
                }                
            }else{
                echo "Please enter username and password";
            }
        }
}
?>        
            

Link to comment
https://forums.phpfreaks.com/topic/276540-rowcount/
Share on other sites

Per the manual: http://php.net/manual/en/pdostatement.rowcount.php

 

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.

Link to comment
https://forums.phpfreaks.com/topic/276540-rowcount/#findComment-1422944
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.