Location: PHPKode > projects > php4flicks movie database > php4flicks_0.4.1g_MU/docs/update_to_rev_f.php
<?
	include('../config/config.php');
	
	$res = mysql_query("SELECT COUNT(*) AS count FROM directs") or die(mysql_error());
	$row = mysql_fetch_array($res);
	$count = $row['count'];
	set_time_limit($count*3);
	
	echo 'updating DIRECTS table structure...<br/><br/>';
	
	/**
	*** DIRECTS table
	**/
	
	mysql_query("CREATE TABLE `directs_new` (`movie_id` MEDIUMINT UNSIGNED NOT NULL, `people_id` MEDIUMINT UNSIGNED NOT NULL)") or die(mysql_error());
	mysql_query("ALTER TABLE `directs_new` ADD PRIMARY KEY (movie_id,people_id)") or die(mysql_error());
	mysql_query("insert into directs_new SELECT DISTINCT movies_u.id As movie_id, directs.people_id FROM directs LEFT JOIN movies_u ON directs.movie_fid=movies_u.fid") or die(mysql_error());
	mysql_query("delete from directs_new where movie_id = 0") or die(mysql_error());
	mysql_query("ALTER TABLE `directs` RENAME `directs_ORIGINAL`") or die(mysql_error());
	mysql_query("ALTER TABLE `directs_new` RENAME `directs`") or die(mysql_error());
	
	$res = mysql_query("SELECT COUNT(*) AS count FROM writes") or die(mysql_error());
	$row = mysql_fetch_array($res);
	$count = $row['count'];
	set_time_limit($count*3);
	
	echo '...completed updating DIRECTS table structure.<br/><br/><br/>';
	echo 'updating WRITES table structure...<br/><br/>';
	
	/**
	*** WRITES table
	**/
	
	mysql_query("CREATE TABLE `writes_new` (`movie_id` MEDIUMINT UNSIGNED NOT NULL, `people_id` MEDIUMINT UNSIGNED NOT NULL)") or die(mysql_error());
	mysql_query("ALTER TABLE `writes_new` ADD PRIMARY KEY (movie_id,people_id)") or die(mysql_error());
	mysql_query("insert into writes_new SELECT DISTINCT movies_u.id As movie_id, writes.people_id FROM writes LEFT JOIN movies_u ON writes.movie_fid=movies_u.fid") or die(mysql_error());
	mysql_query("delete from writes_new where movie_id = 0") or die(mysql_error());
	mysql_query("ALTER TABLE `writes` RENAME `writes_ORIGINAL`") or die(mysql_error());
	mysql_query("ALTER TABLE `writes_new` RENAME `writes`") or die(mysql_error());
	
	$res = mysql_query("SELECT COUNT(*) AS count FROM plays_in") or die(mysql_error());
	$row = mysql_fetch_array($res);
	$count = $row['count'];
	set_time_limit($count*3);
	
	echo '...completed updating WRITES table structure.<br/><br/><br/>';
	echo 'updating PLAYS_IN table structure...<br/><br/>';
	
	/**
	*** PLAYS_IN table
	**/
	
	mysql_query("CREATE TABLE `plays_in_new` (`movie_id` MEDIUMINT UNSIGNED NOT NULL, `people_id` MEDIUMINT UNSIGNED NOT NULL)") or die(mysql_error());
	mysql_query("ALTER TABLE `plays_in_new` ADD PRIMARY KEY (movie_id,people_id)") or die(mysql_error());
	mysql_query("insert into plays_in_new SELECT DISTINCT movies_u.id As movie_id, plays_in.people_id FROM plays_in LEFT JOIN movies_u ON plays_in.movie_fid=movies_u.fid") or die(mysql_error());
	mysql_query("delete from plays_in_new where movie_id = 0") or die(mysql_error());
	mysql_query("ALTER TABLE `plays_in` RENAME `plays_in_ORIGINAL`") or die(mysql_error());
	mysql_query("ALTER TABLE `plays_in_new` RENAME `plays_in`") or die(mysql_error());

	echo '...completed updating PLAYS_IN table structure.';
?>
Return current item: php4flicks movie database