2 require_once(dirname(__FILE__)."/configure.phpl");
\r
5 define("ADDR_ECHO", 0);
\r
6 define("ADDR_GET_INFOMATION", 0);
\r
7 define("ADDR_GET_BALANCE", 1);
\r
8 define("DB_CONNECT",DB.":host=".DB_HOST.";dbname=".DB_NAME);
\r
9 define("PREFIX_SEP_DB","_");
\r
10 define("PREFIX_SEP_MAIL",".");
\r
11 define("TBL","books,users,mails,subscribes,himoku,balance");
\r
12 $ZUBORA["tables"] = explode(",",TBL);
\r
13 foreach($ZUBORA["tables"] as $table){
\r
14 define("TBL_".strtoupper($table),PREFIX.PREFIX_SEP_DB.$table);
\r
21 var $isConnected = false;
\r
22 var $queryResult = null;
\r
25 function ZuboraDB(){}
\r
27 if(!$this->isConnected){
\r
29 $this->pdo = new PDO(DB_CONNECT,DB_USER,DB_PASSWORD);
\r
30 $this->isConnected = true;
\r
32 } catch (PDOException $e) {
\r
33 $this->ERROR .= "DB connection error!: " . $e->getMessage() . "\n";
\r
34 throw new Exception($this->ERROR);
\r
39 function query($sql){
\r
41 return $this->pdo->query($sql);
\r
43 function closeCursor(){
\r
44 return $this->pdo->closeCursor();
\r
47 function isExist($table){
\r
48 if (preg_match("/^[_\-a-z0-9]+$/i",$table)){
\r
49 $q = $this->pdo->prepare("SELECT * FROM ".$table.";");
\r
50 return $q->execute();
\r
52 throw new Exception("Charactor Error!: table name must be [-_0-9a-zA-Z]+\n");
\r
55 function getBook($book,$domain){
\r
57 $stmt = $this->pdo->prepare("SELECT * FROM ".TBL_BOOKS." WHERE book = ? and domain = ?;");
\r
58 $stmt->bindParam(1, $book, PDO::PARAM_STR,30);
\r
59 $stmt->bindParam(2, $domain, PDO::PARAM_STR,250);
\r
60 if(!$stmt->execute()){
\r
61 $er = $stmt->errorInfo();
\r
62 $this->ERROR .= $er[2];
\r
65 return $stmt->fetch(PDO::FETCH_ASSOC);
\r
68 function getMainMailAddr($from){
\r
70 $stmt = $this->pdo->prepare("SELECT mail FROM ".TBL_MAILS." WHERE submail = ?;");
\r
71 $stmt->bindParam(1, $from, PDO::PARAM_STR,250);
\r
72 if(!$stmt->execute()){
\r
73 $er = $stmt->errorInfo();
\r
74 $this->ERROR .= $er[2];
\r
77 $result = $stmt->fetch(PDO::FETCH_ASSOC);
\r
78 if(false === $result){
\r
79 $this->ERROR .= "error! mail addr not found!\n";
\r
82 return $result["mail"];
\r
86 function isSubscribed($book,$mail){
\r
88 $stmt = $this->pdo->prepare("SELECT * FROM ".TBL_SUBSCRIBES." WHERE book = ? and mail = ?;");
\r
89 $stmt->bindParam(1, $book, PDO::PARAM_STR,30);
\r
90 $stmt->bindParam(2, $mail, PDO::PARAM_STR,250);
\r
91 if(!$stmt->execute()){
\r
92 $er = $stmt->errorInfo();
\r
93 $this->ERROR .= $er[2];
\r
96 if(false === $stmt->fetch(PDO::FETCH_ASSOC)){
\r
103 function getHimoku($book,$himoku){
\r
105 $stmt = $this->pdo->prepare("SELECT * FROM ".TBL_HIMOKU." WHERE book = ? and himoku = ?;");
\r
106 $stmt->bindParam(1, $book, PDO::PARAM_STR,30);
\r
107 $stmt->bindParam(2, $himoku, PDO::PARAM_STR,30);
\r
108 if(!$stmt->execute()){
\r
109 $er = $stmt->errorInfo();
\r
110 $this->ERROR .= $er[2];
\r
113 return $stmt->fetch(PDO::FETCH_ASSOC);
\r
116 function addBalance($book,$himoku,$val,$mail,$note){
\r
118 $stmt = $this->pdo->prepare("INSERT INTO ".TBL_BALANCE." (id,book,himoku,val,mail,note,date) VALUES (?,?,?,?,?,?,CURRENT_TIMESTAMP);");
\r
119 $stmt->bindParam(1, md5(uniqid()), PDO::PARAM_STR,32);
\r
120 $stmt->bindParam(2, $book, PDO::PARAM_STR,30);
\r
121 $stmt->bindParam(3, $himoku, PDO::PARAM_STR,30);
\r
122 $stmt->bindParam(4, $val, PDO::PARAM_INT);
\r
123 $stmt->bindParam(5, $mail, PDO::PARAM_STR,250);
\r
124 $stmt->bindParam(6, $note, PDO::PARAM_STR);
\r
125 if(!$stmt->execute()){
\r
126 $er = $stmt->errorInfo();
\r
127 $this->ERROR .= $er[2];
\r