Project

General

Profile

« Previous | Next » 

Revision 1586

Added by darkviper almost 13 years ago

added new method SqlImport() to class database

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12

  
13 13
=========================== add small Features 2.8.2 ==========================
14
24 Jan-2012 Build 1586 Werner v.d.Decken(DarkViper)
15
+ added new method SqlImport() to class database
14 16
19 Jan-2012 Build 1585 Dietmar Woellbrink (Luisehahne)
15 17
# fixed double table width in modify.php form module ((Tks to Ruebenwurzel)
16 18
19 Jan-2012 Build 1584 Dietmar Woellbrink (Luisehahne)
branches/2.8.x/wb/admin/interface/version.php
52 52

  
53 53
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
54 54
if(!defined('VERSION')) define('VERSION', '2.8.2');
55
if(!defined('REVISION')) define('REVISION', '1585');
55
if(!defined('REVISION')) define('REVISION', '1586');
56 56
if(!defined('SP')) define('SP', 'SP2');
branches/2.8.x/wb/framework/class.database.php
282 282
		}
283 283
		return $retval;
284 284
	}
285
/**
286
 * Import a standard *.sql dump file
287
 * @param string $sSqlDump link to the sql-dumpfile
288
 * @param string $sTablePrefix
289
 * @param string $sTblEngine
290
 * @param string $sTblCollation
291
 * @param bool $bPreserve set to true will ignore all DROP TABLE statements
292
 * @return boolean true if import successful
293
 */
294
	public function SqlImport($sSqlDump,
295
	                          $sTablePrefix = '',
296
	                          $sTblEngine = 'ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci',
297
	                          $sTblCollation = ' collate utf8_unicode_ci',
298
	                          $bPreserve = true)
299
	{
300
		$retval = true;
301
		$this->error = '';
302
		$aSearch  = array('{TABLE_PREFIX}','{TABLE_ENGINE}', '{TABLE_COLLATION}');
303
		$aReplace = array($sTablePrefix, $sTblEngine, $sTblCollation);
304
		$sql = '';
305
		$aSql = file($sSqlDump);
306
		while ( sizeof($aSql) > 0 ) {
307
			$sSqlLine = trim(array_shift($aSql));
308
			if (preg_match('/^[-\/].+/', $sSqlLine)) {
309
				$sql = $sql.' '.$sql_line;
310
				if ((substr($sql,-1,1) == ';')) {
311
					$sql = trim(str_replace( $aSearch, $aReplace, $sql));
312
					if (!($bPreserve && preg_match('/^\s*DROP TABLE IF EXISTS/siU', $sql))) {
313
						if(!mysql_query($sql, $this->db_handle)) {
314
							$retval = false;
315
							$this->error = mysql_error($this->db_handle);
316
							unset($aSql);
317
							break;
318
						}
319
					}
320
					$sql = '';
321
				}
322
			}
323
		}
324
		return $retval;
325
	}
285 326

  
286
	/**
287
	* retuns the type of the engine used for requested table
288
	* @param string $table name of the table, including prefix
289
	* @return boolean/string false on error, or name of the engine (myIsam/InnoDb)
290
	*/
327
/**
328
 * retuns the type of the engine used for requested table
329
 * @param string $table name of the table, including prefix
330
 * @return boolean/string false on error, or name of the engine (myIsam/InnoDb)
331
 */
291 332
	public function getTableEngine($table)
292 333
	{
293 334
		$retVal = false;

Also available in: Unified diff