• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database Query result frustration

#1
Hi all,

Am having a hell of a time trying to figure out whats going wrong here or what maybe i am missing. Been troubleshooting this error for far to many hours now.

I am writing a custom login library, but when I query the database for a username/email address, the query is not returning any results at all. 
I ran the same query itself in phpmyadmin and it is finding the result expected there.

So I figure I will put it here and maybe you people might see something my blurring eyes are missing.

Below is the relevant piece code:
PHP Code:
            $sql "SELECT user_id,user_group,username,passwd FROM users WHERE username=?";

            $db_result $this->db->query($sql,[$username]);
            
            
if((!is_array($db_result)) || (!is_object($db_result)) || (count($db_result->getResult() <= 0) || (count($db_result->getResult() > 1)))) {
                return $result = [
                    'status' => FALSE,
                    'header' => 'LOGIN DENIED',
                    'message' => 'Your Login Attempt has been denied. We could not find your login details!'
                ];
            

EDIT
Found the error!
It was in the IF statement itself. It was all syntax errors with the count function that somehow were not being thrown. Not sure if thats a PHP Issue but perhaps the developers could write a wrapper around count for the databases that would simplify it further?

Also one thing that puzzles me though is why is_array() is returning false on the result array when its clearly true?
Reply

#2
(04-12-2020, 08:48 AM)stlake2011 Wrote: Also one thing that puzzles me though is why is_array() is returning false on the result array when its clearly true?

Hello,

Just put:
PHP Code:
var_dump($db_result); 
before the 'if' and you'll get the answer

Vincent
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.