1: <?php
2: /**
3: * Abstract base class for XOOPS Database access classes
4: *
5: * You may not change or alter any portion of this comment or credits
6: * of supporting developers from this source code or any supporting source code
7: * which is considered copyrighted (c) material of the original comment or credit authors.
8: * This program is distributed in the hope that it will be useful,
9: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
13: * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14: * @package kernel
15: * @subpackage database
16: * @since 1.0.0
17: * @author Kazumi Ono <onokazu@xoops.org>
18: */
19:
20: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
21:
22: /**
23: * make sure this is only included once!
24: */
25: if (defined('XOOPS_C_DATABASE_INCLUDED')) {
26: return null;
27: }
28:
29: define('XOOPS_C_DATABASE_INCLUDED', 1);
30:
31: /**
32: * Abstract base class for Database access classes
33: *
34: * @abstract
35: * @author Kazumi Ono <onokazu@xoops.org>
36: * @package kernel
37: * @subpackage database
38: */
39: abstract class XoopsDatabase
40: {
41: /**
42: * Prefix for tables in the database
43: *
44: * @var string
45: */
46: public $prefix = '';
47:
48: /**
49: * reference to a {@link XoopsLogger} object
50: *
51: * @see XoopsLogger
52: * @var object XoopsLogger
53: */
54: public $logger;
55:
56: /**
57: * If statements that modify the database are selected
58: *
59: * @var boolean
60: */
61: public $allowWebChanges = false;
62:
63: /**
64: * XoopsDatabase constructor.
65: */
66: public function __construct()
67: {
68: // exit('Cannot instantiate this class directly');
69: }
70:
71: /**
72: * assign a {@link XoopsLogger} object to the database
73: *
74: * @see XoopsLogger
75: * @param XoopsLogger $logger reference to a {@link XoopsLogger} object
76: */
77:
78: public function setLogger(XoopsLogger $logger)
79: {
80: $this->logger = &$logger;
81: }
82:
83: /**
84: * set the prefix for tables in the database
85: *
86: * @param string $value table prefix
87: */
88: public function setPrefix($value)
89: {
90: $this->prefix = $value;
91: }
92:
93: /**
94: * attach the prefix.'_' to a given tablename
95: *
96: * if tablename is empty, only prefix will be returned
97: *
98: * @param string $tablename tablename
99: * @return string prefixed tablename, just prefix if tablename is empty
100: */
101: public function prefix($tablename = '')
102: {
103: if ($tablename != '') {
104: return $this->prefix . '_' . $tablename;
105: } else {
106: return $this->prefix;
107: }
108: }
109:
110: /**
111: * Test the passed result to determine if it is a valid result set
112: *
113: * @param mixed $result value to test
114: *
115: * @return bool true if $result is a database result set, otherwise false
116: */
117: abstract public function isResultSet($result);
118: }
119:
120: /**
121: * Only for backward compatibility
122: *
123: * @deprecated
124: */
125: class Database
126: {
127: /**
128: * @return object
129: */
130: public function getInstance()
131: {
132: if (is_object($GLOBALS['xoopsLogger'])) {
133: $GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . " is deprecated since XOOPS 2.5.4, please use 'XoopsDatabaseFactory::getDatabaseConnection();' instead.");
134: }
135: $inst = XoopsDatabaseFactory::getDatabaseConnection();
136:
137: return $inst;
138: }
139: }
140: