isConnected){ try{ $this->pdo = new PDO(DB_CONNECT,DB_USER,DB_PASSWORD); $this->isConnected = true; return true; } catch (PDOException $e) { $this->ERROR .= "DB connection error!: " . $e->getMessage() . "\n"; throw new Exception($this->ERROR); } } } /* function query($sql){ $this->connect(); return $this->pdo->query($sql); } function closeCursor(){ return $this->pdo->closeCursor(); } */ function isExist($table){ if (preg_match("/^[_\-a-z0-9]+$/i",$table)){ $q = $this->pdo->prepare("SELECT * FROM ".$table.";"); return $q->execute(); }else{ throw new Exception("Charactor Error!: table name must be [-_0-9a-zA-Z]+\n"); } } function getBook($book,$domain){ $this->connect(); $stmt = $this->pdo->prepare("SELECT * FROM ".TBL_BOOKS." WHERE book = ? and domain = ?;"); $stmt->bindParam(1, $book, PDO::PARAM_STR,30); $stmt->bindParam(2, $domain, PDO::PARAM_STR,250); if(!$stmt->execute()){ $er = $stmt->errorInfo(); $this->ERROR .= $er[2]; return false; }else{ return $stmt->fetch(PDO::FETCH_ASSOC); } } function getMainMailAddr($from){ $this->connect(); $stmt = $this->pdo->prepare("SELECT mail FROM ".TBL_MAILS." WHERE submail = ?;"); $stmt->bindParam(1, $from, PDO::PARAM_STR,250); if(!$stmt->execute()){ $er = $stmt->errorInfo(); $this->ERROR .= $er[2]; return false; }else{ $result = $stmt->fetch(PDO::FETCH_ASSOC); if(false === $result){ $this->ERROR .= "error! mail addr not found!\n"; return false; }else{ return $result["mail"]; } } } function isSubscribed($book,$mail){ $this->connect(); $stmt = $this->pdo->prepare("SELECT * FROM ".TBL_SUBSCRIBES." WHERE book = ? and mail = ?;"); $stmt->bindParam(1, $book, PDO::PARAM_STR,30); $stmt->bindParam(2, $mail, PDO::PARAM_STR,250); if(!$stmt->execute()){ $er = $stmt->errorInfo(); $this->ERROR .= $er[2]; return false; }else{ if(false === $stmt->fetch(PDO::FETCH_ASSOC)){ return false; }else{ return true; } } } function getHimoku($book,$himoku){ $this->connect(); $stmt = $this->pdo->prepare("SELECT * FROM ".TBL_HIMOKU." WHERE book = ? and himoku = ?;"); $stmt->bindParam(1, $book, PDO::PARAM_STR,30); $stmt->bindParam(2, $himoku, PDO::PARAM_STR,30); if(!$stmt->execute()){ $er = $stmt->errorInfo(); $this->ERROR .= $er[2]; return false; }else{ return $stmt->fetch(PDO::FETCH_ASSOC); } } function addBalance($book,$himoku,$val,$mail,$note){ $this->connect(); $stmt = $this->pdo->prepare("INSERT INTO ".TBL_BALANCE." (id,book,himoku,val,mail,note,date) VALUES (?,?,?,?,?,?,CURRENT_TIMESTAMP);"); $stmt->bindParam(1, md5(uniqid()), PDO::PARAM_STR,32); $stmt->bindParam(2, $book, PDO::PARAM_STR,30); $stmt->bindParam(3, $himoku, PDO::PARAM_STR,30); $stmt->bindParam(4, $val, PDO::PARAM_INT); $stmt->bindParam(5, $mail, PDO::PARAM_STR,250); $stmt->bindParam(6, $note, PDO::PARAM_STR); if(!$stmt->execute()){ $er = $stmt->errorInfo(); $this->ERROR .= $er[2]; return false; }else{ return true; } } } ?>