<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 1/11/2011	ELL
// 
//

function copy_table($src_table, $dest_table, $dbh, $database)
{
	$query = "TRUNCATE TABLE " . $dest_table;
	$cnt = $dbh->exec($query);
		
	$query = "SELECT * FROM " . $src_table;
	$result = $dbh->query($query);
	while ($row = $result->fetch(PDO::FETCH_ASSOC))
	{
		$sql = "INSERT INTO " . $dest_table . " SET ";
		$query2 = "SHOW COLUMNS FROM " . $src_table . " FROM " . $database;
		$result2 = $dbh->query($query2);
		while ($column = $result2->fetch(PDO::FETCH_ASSOC))
		{
			if ($column['Field'] != "id")
			{
				if (strpos($sql, "=")) 
					$sql .= ", ";
				$field = $column['Field'];
				$sql .= "`" . $field . "` = '" . addslashes($row[$field]) . "'";
			}
		}
//		echo "sql: $sql\n<br><br>\n";
		$cnt = $dbh->exec($sql);
	}
}
	
?>