comparison classes/basemodel.php @ 47:886f43b26ee2 extractapp

move/remove develop folder
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 17 Mar 2015 10:54:13 +0100
parents
children 840cdb52f476
comparison
equal deleted inserted replaced
46:b3ca5d2b4d3f 47:886f43b26ee2
1 <?php
2
3 abstract class BaseModel {
4
5 /*
6 protected $get_text_from_fileId_url = "http://localgazetteers-dev/LGServer/rest/text/getFileText?fileId=";
7 protected $get_text_from_sectionId_url = "http://localgazetteers-dev/LGServer/rest/text/getSectionText?sectionId=";
8 protected $save_to_LGService_url = "http://localgazetteers-dev/LGServer/rest/text/save";
9 protected $save_new_to_LGService_url = "http://localgazetteers-dev/LGServer/rest/text/saveNew";
10
11 */
12 protected $get_text_from_fileId_url, $get_text_from_sectionId_url, $save_to_LGService_url, $save_new_to_LGService_url;
13
14 public function __construct() {
15 global $mysql_database, $mysql_server, $mysql_user, $mysql_password, $systemNAME, $lgserver_url;
16 $this->systemNAME = $systemNAME;
17
18 $this->get_text_from_fileId_url = $lgserver_url."rest/text/getFileText?fileId=";
19 $this->get_text_from_sectionId_url = $lgserver_url."rest/text/getSectionText?sectionId=";
20 $this->save_to_LGService_url = $lgserver_url."rest/text/save";
21 $this->save_new_to_LGService_url = $lgserver_url."rest/text/saveNew";
22
23 set_time_limit(0);
24 ini_set('memory_limit', '-1');
25
26 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password);
27 mysql_query("SET NAMES utf8");
28
29 if (!$link_mysql) {
30 die('Could not connect: ' . mysql_error());
31 }
32 $db_selected = mysql_select_db($mysql_database, $link_mysql);
33 if (!$db_selected) {
34
35 die ('Can\'t use foo : ' . mysql_error());
36 }
37 $this->topic = 2; // set the default topic to product_name (物產)
38 }
39
40 protected function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
41 $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
42
43 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
44
45 switch ($theType) {
46 case "text":
47 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
48 break;
49 case "long":
50 case "int":
51 $theValue = ($theValue != "") ? intval($theValue) : "NULL";
52 break;
53 case "double":
54 $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
55 break;
56 case "date":
57 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
58 break;
59 case "defined":
60 $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
61 break;
62 }
63 return $theValue;
64 }
65
66 protected function GetWordlist() {
67 $query = sprintf("SELECT * FROM `wordlist` WHERE `systemName`='%s' ORDER BY `name` ASC", $this->systemNAME);
68 $result = mysql_query($query);
69 if (!$result){
70 return json_encode("Failed during selecting wordlist table.");;
71 }
72 return $result;
73 }
74
75 protected function GetSectionsByID($section_id) {
76 $query = sprintf("SELECT * FROM `sections` WHERE `id`=\"%s\"", $section_id);
77 $result = mysql_query($query);
78 if (!$result){
79 echo json_encode("Failed during selecting sections table");
80 return;
81 }
82 return $result;
83 }
84
85 protected function GetTaglist() {
86 $query = sprintf("SELECT * FROM `taglist` WHERE `systemName`='%s' ORDER BY `tag` ASC", $this->systemNAME);
87 $result = mysql_query($query);
88 if (!$result) {
89 return json_encode("Failed during selecting taglist table.");
90 }
91 return $result;
92 }
93
94 protected function GetBooksByID($bookId) {
95 $query = sprintf("SELECT * FROM `books` WHERE id=\"%s\"", $bookId);
96 $result = mysql_query($query);
97 if (!$result) {
98 return json_encode("Failed during selecting books table.");
99 }
100 return $result;
101 }
102
103 protected function GetTopiclist() {
104 $query = sprintf("SELECT * FROM `topics`");
105 $result = mysql_query($query);
106 if (!$result) {
107 return json_encode("Failed during selecting topics table.");
108 }
109 return $result;
110 }
111
112 protected function GetTopicByID($topic_id) {
113 $query = sprintf("SELECT * FROM `topics` WHERE id=\"%s\"", $topic_id);
114 $result = mysql_query($query);
115 if (!$result) {
116 return json_encode("Failed during selecting topics table.");
117 }
118 return $result;
119 }
120
121
122 }
123
124 ?>