Project

General

Profile

« Previous | Next » 

Revision 1586

Added by darkviper over 12 years ago

added new method SqlImport() to class database

View differences:

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