[solved] PDO is driving me crazy :/

Ask about a PHP problem here.
Post Reply
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

[solved] PDO is driving me crazy :/

Post by Helx »

Hi,

I have been trying to use PDO instead of the basic MySQL (I was told it may be deprecated). I keep getting this error:

Fatal error: Call to a member function rowCount() on a non-object in /home/stratusc/public_html/cgi-bin/ip-only/bta/action.php on line 70


My code is this: (WARNING HORRIBLE SYNTAX)
[syntax=php]if($_GET['do'] == 'login'){
$email = base64_encode('someGuy@me.com');
$email = str_replace('=','',$email);
$pass = 'test';

$filter1 = hash('gost', $email);
$salt = $db2->query("select * from salt where email = '".$filter1."'");
$salt = $salt->fetch();
$coresalt = $salt['coresalt'];
$salt1 = $salt['salt1'];
$salt2 = $salt['salt2'];
$salt3 = $salt['salt3'];

$pass = enc($pass,$email,$coresalt,$salt1,$salt2,$salt3);
$login_check = $db1->query("select * from usr where email = '$user' and password = '$pass' limit 1");
$login_check = $login_check->fetch();
$login_check = $login_check->rowCount();

if($login_check == 1){
echo 'Yes!';
}else{
echo 'No.';
}
die();
}[/syntax]

I'll try to explain what went on in my head to do this...
Well, all emails are stored in the SEPARATE password salts DB with a bit of base64 (to throw hackers off, if they gain access to my DB ;) ) Then they are hashed in GOST. No idea why.

But basically, what I want is to count the number of rows with PDO. I have no clue how to stop this error. When I commented out all of the problematic code, it always said 'Yes!' no matter what I changed the password to.

Please help me :?

Oh, and i was told that if I prepare() then execute() I wouldn't need to do any sort of stripping. Is this true?

(Sorry if this made no sense, I haven't had any sleep in a long time...)
Last edited by Helx on Mon Sep 10, 2012 8:09 am, edited 1 time in total.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PDO is driving me crazy :/

Post by jacek »

fetch() actually fetches the data doesn't it ? So you would not want that there at all, or at least put it after the rowCount().

It would be worth adding a few var_dump() calls around the problematic area

[syntax=php] $login_check = $db1->query("select * from usr where email = '$user' and password = '$pass' limit 1");
var_dump($login_check);
$login_check = $login_check->fetch();
var_dump($login_check);
$login_check = $login_check->rowCount();
var_dump($login_check);[/syntax]

which will show you the value of the variable at each stage, one of them will probably be NULL.
Image
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: PDO is driving me crazy :/

Post by Helx »

I put a var_dump under the query:

[syntax=text]object(PDOStatement)#3 (1) { ["queryString"]=> string(207) "select * from usr where email = 'THISISMYEMAIL' and password = 'MAYHASHEDPASSWORDLOL' limit 1" } [/syntax]

Nothing would show if I put it under any of the other statements.
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: PDO is driving me crazy :/

Post by Helx »

Oh wow... Turns out I had changed the way I stored the passwords without me knowing... :3

Solved. Thanks for help anyway :)
Post Reply