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
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.

Edited by Psycho
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.