2 require_once(dirname(__FILE__)."/configure.phpl");
\r
7 define("ADDR_ECHO", 0);
\r
8 define("ADDR_GET_INFOMATION", 0);
\r
9 define("ADDR_GET_BALANCE", 1);
\r
10 define("DB_CONNECT",DB.":host=".DB_HOST.";dbname=".DB_NAME);
\r
11 define("PREFIX_SEP_DB","_");
\r
12 define("PREFIX_SEP_MAIL",".");
\r
13 define("TBL","books,users,mails,subscribes,himoku,balance");
\r
14 $ZUBORA["tables"] = explode(",",TBL);
\r
15 foreach($ZUBORA["tables"] as $table){
\r
16 define("TBL_".strtoupper($table),PREFIX.PREFIX_SEP_DB.$table);
\r
23 var $isConnected = false;
\r
24 var $queryResult = null;
\r
27 function ZuboraDB(){}
\r
29 if(!$this->isConnected){
\r
31 $this->pdo = new PDO(DB_CONNECT,DB_USER,DB_PASSWORD);
\r
32 $this->isConnected = true;
\r
34 } catch (PDOException $e) {
\r
35 $this->ERROR .= "DB connection error!: " . $e->getMessage() . "\n";
\r
36 throw new Exception($this->ERROR);
\r
41 function query($sql){
\r
43 return $this->pdo->query($sql);
\r
45 function closeCursor(){
\r
46 return $this->pdo->closeCursor();
\r
49 function isExist($table){
\r
50 if (preg_match("/^[_\-a-z0-9]+$/i",$table)){
\r
51 $q = $this->pdo->prepare("SELECT * FROM ".$table.";");
\r
52 return $q->execute();
\r
54 throw new Exception("Charactor Error!: table name must be [-_0-9a-zA-Z]+\n");
\r
57 function getBook($book,$domain){
\r
59 $stmt = $this->pdo->prepare("SELECT * FROM ".TBL_BOOKS." WHERE book = ? and domain = ?;");
\r
60 $stmt->bindParam(1, $book, PDO::PARAM_STR,30);
\r
61 $stmt->bindParam(2, $domain, PDO::PARAM_STR,250);
\r
62 if(!$stmt->execute()){
\r
63 $er = $stmt->errorInfo();
\r
64 $this->ERROR .= $er[2];
\r
67 return $stmt->fetch(PDO::FETCH_ASSOC);
\r
70 function getMainMailAddr($from){
\r
72 $stmt = $this->pdo->prepare("SELECT mail FROM ".TBL_MAILS." WHERE submail = ?;");
\r
73 $stmt->bindParam(1, $from, PDO::PARAM_STR,250);
\r
74 if(!$stmt->execute()){
\r
75 $er = $stmt->errorInfo();
\r
76 $this->ERROR .= $er[2];
\r
79 $result = $stmt->fetch(PDO::FETCH_ASSOC);
\r
80 if(false === $result){
\r
81 $this->ERROR .= "error! mail addr not found!\n";
\r
84 return $result["mail"];
\r
88 function isSubscribed($book,$mail){
\r
90 $stmt = $this->pdo->prepare("SELECT * FROM ".TBL_SUBSCRIBES." WHERE book = ? and mail = ?;");
\r
91 $stmt->bindParam(1, $book, PDO::PARAM_STR,30);
\r
92 $stmt->bindParam(2, $mail, PDO::PARAM_STR,250);
\r
93 if(!$stmt->execute()){
\r
94 $er = $stmt->errorInfo();
\r
95 $this->ERROR .= $er[2];
\r
98 if(false === $stmt->fetch(PDO::FETCH_ASSOC)){
\r
105 function getHimoku($book,$himoku){
\r
107 $stmt = $this->pdo->prepare("SELECT * FROM ".TBL_HIMOKU." WHERE book = ? and himoku = ?;");
\r
108 $stmt->bindParam(1, $book, PDO::PARAM_STR,30);
\r
109 $stmt->bindParam(2, $himoku, PDO::PARAM_STR,30);
\r
110 if(!$stmt->execute()){
\r
111 $er = $stmt->errorInfo();
\r
112 $this->ERROR .= $er[2];
\r
115 return $stmt->fetch(PDO::FETCH_ASSOC);
\r
118 function addBalance($book,$himoku,$val,$mail,$note){
\r
120 $stmt = $this->pdo->prepare("INSERT INTO ".TBL_BALANCE." (id,book,himoku,val,mail,note,date) VALUES (?,?,?,?,?,?,CURRENT_TIMESTAMP);");
\r
121 $stmt->bindParam(1, md5(uniqid()), PDO::PARAM_STR,32);
\r
122 $stmt->bindParam(2, $book, PDO::PARAM_STR,30);
\r
123 $stmt->bindParam(3, $himoku, PDO::PARAM_STR,30);
\r
124 $stmt->bindParam(4, $val, PDO::PARAM_INT);
\r
125 $stmt->bindParam(5, $mail, PDO::PARAM_STR,250);
\r
126 $stmt->bindParam(6, $note, PDO::PARAM_STR);
\r
127 if(!$stmt->execute()){
\r
128 $er = $stmt->errorInfo();
\r
129 $this->ERROR .= $er[2];
\r