note 87393 added to pdo.query
| From: | george at example dot com | Date: | Wed, 03 Dec 2008 14:23:07 +0000 |
| Subject: | note 87393 added to pdo.query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-147583@lists.php.net to get a copy of this message | ||
I am trying to convert a MySQL login script, into PDO. I am struggling to do this. I have not used
PDO before, only MySQL, so have learned about magic quotes ect. How could i convert my script, into
PDO ?
<?PHP
function confirmUser($username, $password){
global $db;
/* Add slashes if necessary (for query) */
if(!get_magic_quotes_gpc()) {
$email = addslashes($username);
}
/* Verify that user is in database */
$q1 = $db->query("SELECT password FROM user WHERE email = '$username'");
//$result = ($q1,$db);
if ($q1->fetchColumn()) {
// if(!$result || (mysql_numrows($result) < 1)){
return 1; //Indicates email failure
}
/* Retrieve password from result, strip slashes */
$dbarray = mysql_fetch_array($result);
$dbarray['password'] = stripslashes($dbarray['password']);
$password = stripslashes($password);
/* Validate that password is correct */
if($password == $dbarray['password']){
$q2 = $db->query("UPDATE user SET lastlogin='". date("Y-m-d
H:i:s",time())."' where
email='".$_SESSION['username']."' and
password='".$_SESSION['password']."'");
//mysql_query($q,$db);
return 0; //Success! Username and password confirmed
}
else{
return 2; //Indicates password failure
}
}
?>
----
Server IP: 87.124.35.190
Probable Submitter: 92.10.25.211
----
Manual Page -- http://www.php.net/manual/en/pdo.query.php
Edit -- https://master.php.net/note/edit/87393
Del: integrated -- https://master.php.net/note/delete/87393/integrated
Del: useless -- https://master.php.net/note/delete/87393/useless
Del: bad code -- https://master.php.net/note/delete/87393/bad+code
Del: spam -- https://master.php.net/note/delete/87393/spam
Del: non-english -- https://master.php.net/note/delete/87393/non-english
Del: in docs -- https://master.php.net/note/delete/87393/in+docs
Del: other reasons-- https://master.php.net/note/delete/87393
Reject -- https://master.php.net/note/reject/87393
Search -- https://master.php.net/manage/user-notes.php