String comparision issue with change of databases
| From: | Tamkhane, Pravin | Date: | Fri, 23 Nov 2007 12:07:03 +0000 |
| Subject: | String comparision issue with change of databases | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-44357@lists.php.net to get a copy of this message | ||
Hi All,
I am trying to write a simple user verification(not using MD5 hash) . I have users table in database which contains login_id and passwd for registered users. I am using PDO for this purpose. If i use MySQL database, following code for user verification works well without any problem. But if change $dsn to use PostgreSQL database, code fails at if( $passwd === $records[0]['passwd']). After some experiementation, I realized that $passwd holds password string ( assume '1234' for time being) In case of MySQL $records[0]['passwd'] holds password string '1234' as expected and code works. But in case of PostgreSQL, $records[0]['passwd'] holds 1234 rather than '1234' and hence comparison fails. Since I am using same code to register users in both cases, I doubt there would be any issue there.
{
$loginId = $_REQUEST['loginid'];
$passwd = $_REQUEST['passwd'];
$dsn = "mysql:host=$hostName;dbname=$dbName";
$query = "SELECT * FROM users WHERE login_id='$loginId';";
$dbh = new PDO($dsn, $userName, $passWd);
$result = $dbh->query($query);
$records = $result->fetchAll(PDO::FETCH_ASSOC);
if(!count($records))
{
echo '<br/>User does not exist! <A href="registeruser.html">Get Resgitered Now!!</A>';
}
else
{
if( $passwd === $records[0]['passwd'])
{
echo '<br/>User<b> '.$loginId.'</b> logged in successfully!';
}
else
{
echo '<br/>Invalid Password! <A href="index.html">Try Again</A>';
}
}
$dbh = null;
}
Any pointers please? Any hints?
Thanks,
Pravin