Use this code SHOW TABLES
query returns the all tables in your selected db.
$tablesRes = mysql_query('SHOW TABLES',$conn);
while($row = mysql_fetch_row($tablesRes)){
$tables[] = $row[0];
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=export.csv');
foreach($tables as $table){
$query = 'SELECT * FROM '.$table;
$result = mysql_query($query, $conn) or die(mysql_error($conn));
//your csv code here
}