Location: PHPKode > projects > Katropine DBmanager > dbmanager/db2mysql2pro/Csv_Export.php
<?php
class Csv_Export{
	
	public static function __table($econfig){
		if(empty($econfig['table'])){
			$db = new Mysql_DB();
			$tables = $db->tables;
		}else{
			$tables[] = $econfig['table'];
		}
		foreach ($tables as $table){
			if(is_object($table)){
				$tbl = $table->Name;
			}else{
				$tbl = $table;
			}
			$dump .= self::exportTableCSV($econfig, $tbl);
		}
		return $dump;
	}
	
	protected function exportTableCSV($econfig, $table){
		global $link;
		$mysqlOBJ = new Mysql_Data_Handler($link, '', true);
		$data='';
		$result = $mysqlOBJ->__dataTable("SELECT * FROM {$table}");
		$num_rows   = $mysqlOBJ->__dataNum_rows();
		$num_fields = $mysqlOBJ->__dataNum_fields();
		if($num_rows != false){
			if($econfig['fields_first_row'] == true){
				$x = 0;
				foreach (array_keys($result[0]) as $key){
					$data .= $econfig['fields_enclosed'].stripslashes($key).$econfig['fields_enclosed'];
					$data .= ($x < ($num_fields - 1)) ? $econfig['fields_teriminated'] : false;
					$x++;
				}
				$data .= "\n";
			}
			foreach ($result as $red){
				$x = 0;
				foreach ($red as $key=>$val){
				$field_name = $key;
				if($econfig['fields_escaped'] == ''){
					$data .= $red[$field_name];
				}else{
					if(strtoupper($econfig['lines_teriminated']) == 'AUTO' || $econfig['lines_teriminated'] == ''){
						$lines_teriminated = "\n";
					}
					if(is_null($red[$field_name])){
						$red[$field_name] = $econfig['replace_null'];
					}
					$data .= $econfig['fields_enclosed']
							 .str_replace($econfig['fields_enclosed'], $econfig['fields_escaped'].$econfig['fields_enclosed'], str_replace($econfig['fields_escaped'], $econfig['fields_escaped'].$econfig['fields_escaped'], $red[$field_name]))
							 .$econfig['fields_enclosed'];
				
				}
				$data .= ($x < ($num_fields - 1)) ? $econfig['fields_teriminated'] : false;
				$x++;
				}
				
				$data .= $lines_teriminated;
			}
		}
		
		
	return $data;
	}
}
?>
Return current item: Katropine DBmanager