Sigleton DB connection tripping on itself

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Good Day List,
 
I have a singleton DB connection that I am trying to use throughout my
application but It keeps tripping on itself.
 
My main question is: If I am in the middle of a transaction can I
prepare multiple statements eand execute them or will this cause an
error?
 
Here is a code example that tries to reset a users password:
$login = SOME_LOGIN;
 
$sql = "SELECT " . USER_TABLE_ID . " FROM " . USER_TABLE . " " .
         "WHERE " . USER_TABLE_LOGIN . " = :login;";
 
  try {
   $this->db->beginTransaction();
   $stmt = $this->db->prepare($sql);
   $stmt->execute(array(':login' => $login));
   $rs   = $stmt->fetchAll(PDO::FETCH_ASSOC);
 
   // MAKE SURE THERE IS ONLY ONE USER WITH THIS LOGIN
   if (count($rs) != 1) {
    $this->db->rollBack();
    $stmt = null;
    return false;
   }
   // ONLY ONE USER RETURNED - UPDATE PASSWORD
   if ($password = $this->generatePassword()) {
 
    $sql = "UPDATE " . USER_TABLE . " " .
           "SET " . USER_TABLE_PWD . " = '";
           if ($this->sha1) {
         $sql .= sha1($password);
        }else {
         $sql .= $password;
        }
        $sql .= "' " .
        "WHERE " . USER_TABLE_ID . " = :userid;";
 
    $stmt = $this->db->prepare($sql);
    $stmt->execute(array(':userid' => $rs[0][USER_TABLE_ID]));
    $this->db->commit();
    $stmt = null;
    return $password;
   }
   // COULD NOT GENERATE NEW PASSWORD
   else {
    $this->db->rollBack();
    $stmt = null;
    return false;
   }
  }catch (PDOException $e) {
   $this->db->rollBack();
   $stmt = null;
   return false;
  }
 
Ken Vandegrift
kvandegrift@xxxxxxxxxx <mailto:kvandegrift@xxxxxxxxxx> 
Web Administrator
Sharis Mgmt. Corp
 

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux