Esempio n. 1
0
	/**
	 * Outputs a MYSQL table or list of tables to an Excel doc
	 * 
	 * @param string $host
	 *        	MySQL host to connect to
	 * @param string $username
	 *        	Username to connect with
	 * @param string $password
	 *        	Password to connect with
	 * @param string $db
	 *        	Database to use
	 * @param mixed $table
	 *        	If string, out specific table. If array, each table will have
	 *        	it's own sheet
	 * @param mixed $alternateName
	 *        	For multiple tables this does nothing. For table, overrides
	 *        	auto naming of the sheet (table name)
	 */
	public function mysqlTableDump($host, $username, $password, $db, $table, $alternateName = null) {
		EWXcheckDriverDB ( 'mysql' );
		if (empty ( $host ))
			$this->addError ( 'Database', 'HOSTNAME is empty' );
		if (empty ( $username ))
			$this->addError ( 'Database', 'USERNAME is empty' );
		if (empty ( $db ))
			$this->addError ( 'Database', 'DB is empty' );
		if (empty ( $table ))
			$this->addError ( 'Database', 'TABLE(S) is empty' );
		if (count ( $this->formatErrors ) > 0) {
			$this->showErrorSheet ();
			return false;
		}
		
		$link = mysql_connect ( $host, $username, $password );
		if (! $link)
			$this->addError ( 'Database', 'UNABLE to connect to ' . $host . '(' . mysql_error () . ')' );
		if (count ( $this->formatErrors ) > 0) {
			$this->showErrorSheet ();
			return false;
		}
		
		$db_selected = mysql_select_db ( $db );
		if (! $db_selected)
			$this->addError ( 'Database', 'DB "' . $db . '" does not exist' );
		if (count ( $this->formatErrors ) > 0) {
			$this->showErrorSheet ();
			return false;
		}
		
		if (gettype ( $table ) == 'array') {
			foreach ( $table as $table2 ) {
				$sheet = $this->addSheet ( $table2 );
				$query = 'SELECT * FROM `' . $db . '`.`' . $table2 . '` ';
				EWXmysqlGenerateByQuery ( $sheet, $link, $query );
			}
		} else {
			if ($alternateName == null || empty ( $alternateName ))
				$sheet = $this->addSheet ( $table );
			else
				$sheet = $this->addSheet ( $alternateName );
			$query = 'SELECT * FROM `' . $db . '`.`' . $table . '` ';
			EWXmysqlGenerateByQuery ( $sheet, $link, $query );
		}
		if (count ( $this->formatErrors ) > 0) {
			$this->showErrorSheet ();
			return false;
		}
	}
Esempio n. 2
0
	/**
	 * Outputs a MYSQL table or list of tables to an Excel doc
	 * 
	 * @param string $host
	 *        	MySQL host to connect to
	 * @param string $username
	 *        	Username to connect with
	 * @param string $password
	 *        	Password to connect with
	 * @param string $db
	 *        	Database to use
	 * @param mixed $table
	 *        	If string, out specific table. If array, each table will have
	 *        	it's own sheet
	 */
	public function mysqlQueryToTable($host, $username, $password, $query) {
		EWXcheckDriverDB ( 'mysql' );
		if (empty ( $host ))
			$this->addError ( 'Database', 'HOSTNAME is empty' );
		if (empty ( $username ))
			$this->addError ( 'Database', 'USERNAME is empty' );
		if (count ( $this->formatErrors ) > 0) {
			return false;
		}
		
		$link = mysql_connect ( $host, $username, $password );
		if (! $link)
			$this->addError ( 'Database', 'UNABLE to connect to ' . $host . '(' . mysql_error () . ')' );
		if (count ( $this->formatErrors ) > 0) {
			return false;
		}
		
		EWXmysqlGenerateByQuery ( $this, $link, $query );
	}