Mercurial > hg > extraction-interface
comparison develop/classes/basemodel.php @ 6:63e08b98032f
rewrite extraction interface into PHP MVC architecture.
(Although js hasn't been rewritten into MVC, it's fitted into the current PHP MVC architecture.)
- The root of the new PHP MVC is at 'develop/'.
- extraction interface is called "Extractapp" with several action, eg TaggingText, EditWordlist, EditTaglist, ExportTable.
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 05 Feb 2015 16:07:53 +0100 |
parents | |
children | 54a235d43694 |
comparison
equal
deleted
inserted
replaced
5:cbbb7ef22394 | 6:63e08b98032f |
---|---|
1 <?php | |
2 | |
3 abstract class BaseModel { | |
4 // protected $database; | |
5 protected $systemNAME; | |
6 | |
7 public function __construct() { | |
8 global $mysql_database, $mysql_server, $mysql_user, $mysql_password, $systemNAME; | |
9 $this->systemNAME = $systemNAME; | |
10 | |
11 // $this->database = new PDO("mysql:host=localhost;dbname=test", "username", "password"); | |
12 set_time_limit(0); | |
13 ini_set('memory_limit', '-1'); | |
14 | |
15 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); | |
16 mysql_query("SET NAMES utf8"); | |
17 | |
18 if (!$link_mysql) { | |
19 die('Could not connect: ' . mysql_error()); | |
20 } | |
21 $db_selected = mysql_select_db($mysql_database, $link_mysql); | |
22 if (!$db_selected) { | |
23 | |
24 die ('Can\'t use foo : ' . mysql_error()); | |
25 } | |
26 } | |
27 | |
28 protected function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { | |
29 $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; | |
30 | |
31 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); | |
32 | |
33 switch ($theType) { | |
34 case "text": | |
35 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
36 break; | |
37 case "long": | |
38 case "int": | |
39 $theValue = ($theValue != "") ? intval($theValue) : "NULL"; | |
40 break; | |
41 case "double": | |
42 $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; | |
43 break; | |
44 case "date": | |
45 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
46 break; | |
47 case "defined": | |
48 $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; | |
49 break; | |
50 } | |
51 return $theValue; | |
52 } | |
53 | |
54 protected function GetWordlist() { | |
55 $query = sprintf("SELECT * FROM `wordlist` WHERE `systemName`='%s' ORDER BY `name` ASC", $this->systemNAME); | |
56 $result = mysql_query($query); | |
57 if (!$result){ | |
58 return json_encode("Failed during selecting wordlist table.");; | |
59 } | |
60 return $result; | |
61 } | |
62 | |
63 protected function GetSectionsByID($section_id) { | |
64 $query = sprintf("SELECT * FROM `sections` WHERE `id`=\"%s\"", $section_id); | |
65 $result = mysql_query($query); | |
66 if (!$result){ | |
67 echo json_encode("Failed during selecting sections table"); | |
68 return; | |
69 } | |
70 return $result; | |
71 } | |
72 | |
73 protected function GetTaglist() { | |
74 $query = sprintf("SELECT * FROM `taglist` WHERE `systemName`='%s' ORDER BY `tag` ASC", $this->systemNAME); | |
75 $result = mysql_query($query); | |
76 if (!$result) { | |
77 return json_encode("Failed during selecting taglist table."); | |
78 } | |
79 return $result; | |
80 } | |
81 | |
82 protected function GetBooksByID($bookId) { | |
83 $query = sprintf("SELECT * FROM `books` WHERE id=\"%s\"", $bookId); | |
84 $result = mysql_query($query); | |
85 if (!$result) { | |
86 return json_encode("Failed during selecting books table."); | |
87 } | |
88 return $result; | |
89 } | |
90 | |
91 | |
92 | |
93 } | |
94 | |
95 ?> |