Project

General

Profile

« Previous | Next » 

Revision 1866

Added by Dietmar over 11 years ago

  1. typofix in class TranslateTable
    ! framework/functions.php set function create_access_file to deprecated
    ! set ModLanguage.php to deprecated
    ! add methode escapeString to class WbDatabase
    ! update upgrade-script.php
    ! add getter property LastInsertId to class WbDatabase

View differences:

WbDatabase.php
1 1
<?php
2 2
/**
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 4
 *
4
 * @category        framework
5
 * @package         database
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link            http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource      $HeadURL$
15
 * @lastmodified    $Date$
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
16 9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17
 */
18
/*
19
Database class
20
This class will be used to interface between the database
21
and the Website Baker code
22
*/
18
/**
19
 * WbDatabase.php
20
 *
21
 * @category     Core
22
 * @package      Core_database
23
 * @author       Werner v.d.Decken <wkl@isteam.de>
24
 * @author       Dietmar W. <dietmar.woellbrink@websitebaker.org>
25
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
26
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
27
 * @version      0.0.9
28
 * @revision     $Revision$
29
 * @lastmodified $Date$
30
 * @deprecated   from WB version number 2.9
31
 * @description  Mysql database wrapper for use with websitebaker up to version 2.8.4
32
 */
33

  
23 34
/* -------------------------------------------------------- */
24
// Must include code to stop this file being accessed directly
25
if(!defined('WB_PATH')) {
26
	require_once(dirname(__FILE__).'/globalExceptionHandler.php');
27
	throw new IllegalFileException();
28
}
29
/* -------------------------------------------------------- */
30 35
define('DATABASE_CLASS_LOADED', true);
31 36

  
32

  
33 37
class WbDatabase {
34 38

  
35 39
	private static $_oInstances = array();
36 40

  
37 41
	private $_db_handle = null; // readonly from outside
38
	private $_scheme    = 'mysql';
39
	private $_hostname  = 'localhost';
40
	private $_username  = '';
41
	private $_password  = '';
42
	private $_hostport  = '3306';
43 42
	private $_db_name   = '';
44 43
	private $connected  = false;
45 44
	private $error      = '';
......
84 83
	public function doConnect($url = '') {
85 84
		if($url != '') {
86 85
			$aIni = parse_url($url);
87
			$this->_scheme   = isset($aIni['scheme']) ? $aIni['scheme'] : 'mysql';
88
			$this->_hostname = isset($aIni['host']) ? $aIni['host'] : '';
89
			$this->_username = isset($aIni['user']) ? $aIni['user'] : '';
90
			$this->_password = isset($aIni['pass']) ? $aIni['pass'] : '';
91
			$this->_hostport = isset($aIni['port']) ? $aIni['port'] : '3306';
92
			$this->_hostport = $this->_hostport == '3306' ? '' : ':'.$this->_hostport;
93
			$this->_db_name  = ltrim(isset($aIni['path']) ? $aIni['path'] : '', '/\\');
86
			
87
			$scheme   = isset($aIni['scheme']) ? $aIni['scheme'] : 'mysql';
88
			$hostname = isset($aIni['host']) ? $aIni['host'] : '';
89
			$username = isset($aIni['user']) ? $aIni['user'] : '';
90
			$password = isset($aIni['pass']) ? $aIni['pass'] : '';
91
			$hostport = isset($aIni['port']) ? $aIni['port'] : '3306';
92
			$hostport = $hostport == '3306' ? '' : ':'.$hostport;
93
			$db_name  = ltrim(isset($aIni['path']) ? $aIni['path'] : '', '/\\');
94
			$this->_db_name = $db_name;
94 95
		}else {
95 96
			throw new RuntimeException('Missing parameter: unable to connect database');
96 97
		}
97
		$this->_db_handle = mysql_connect($this->_hostname.$this->_hostport,
98
		                                  $this->_username,
99
		                                  $this->_password);
98
		$this->_db_handle = mysql_connect($hostname.$hostport,
99
		                                  $username,
100
		                                  $password);
100 101
		if(!$this->_db_handle) {
101
			throw new RuntimeException('unable to connect \''.$this->_scheme.'://'.
102
			                           $this->_hostname.$this->_hostport.'\'');
102
			throw new RuntimeException('unable to connect \''.$scheme.'://'.
103
			                           $hostname.$hostport.'\'');
103 104
		} else {
104
			if(!mysql_select_db($this->_db_name)) {
105
				throw new RuntimeException('unable to select database \''.$this->_db_name.
106
				                           '\' on \''.$this->_scheme.'://'.
107
				                           $this->_hostname.$this->_hostport.'\'');
105
			if(!mysql_select_db($db_name)) {
106
				throw new RuntimeException('unable to select database \''.$db_name.
107
				                           '\' on \''.$scheme.'://'.
108
				                           $hostname.$hostport.'\'');
108 109
			} else {
109 110
				$this->connected = true;
110 111
			}
......
170 171
		return $this->error;
171 172
	}
172 173

  
174
	// Return escape_string
173 175
/**
176
 * escape a string for use in DB
177
 * @param string 
178
 * @return string
179
 */	
180
	public function escapeString($string) {
181
		return mysql_real_escape_string($string, $this->_db_handle);
182
	}
183

  
184
/**
174 185
 * default Getter for some properties
175
 * @param string $sPropertyName
186
 * @param string name of the Property
176 187
 * @return mixed NULL on error or missing property
177 188
 */
178 189
	public function __get($sPropertyName)
......
183 194
			case 'getDbHandle':
184 195
				$retval = $this->_db_handle;
185 196
				break;
197
			case 'LastInsertId':
198
				$retval = mysql_insert_id($this->_db_handle);
199
				break;
186 200
			case 'db_name':
187 201
			case 'DbName':
188 202
			case 'getDbName':
......
199 213
	} // __get()
200 214

  
201 215
/*
202
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
203
 * @param string $field_name: name of the field to seek for
204
 * @return bool: true if field exists
216
 * @param string full name of the table (incl. TABLE_PREFIX)
217
 * @param string name of the field to seek for
218
 * @return bool true if field exists
205 219
 */
206 220
	public function field_exists($table_name, $field_name)
207 221
	{
......
211 225
	}
212 226

  
213 227
/*
214
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
215
 * @param string $index_name: name of the index to seek for
216
 * @return bool: true if field exists
228
 * @param string full name of the table (incl. TABLE_PREFIX)
229
 * @param string name of the index to seek for
230
 * @return bool true if field exists
217 231
 */
218 232
	public function index_exists($table_name, $index_name, $number_fields = 0)
219 233
	{
......
241 255
	}
242 256

  
243 257
/*
244
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
245
 * @param string $field_name: name of the field to add
246
 * @param string $description: describes the new field like ( INT NOT NULL DEFAULT '0')
247
 * @return bool: true if successful, otherwise false and error will be set
258
 * @param string full name of the table (incl. TABLE_PREFIX)
259
 * @param string name of the field to add
260
 * @param string describes the new field like ( INT NOT NULL DEFAULT '0')
261
 * @return bool true if successful, otherwise false and error will be set
248 262
 */
249 263
	public function field_add($table_name, $field_name, $description)
250 264
	{

Also available in: Unified diff