Location: PHPKode > projects > PushOk SEMA > convert01to02.php
<?PHP

$pok_mysql_server = "localhost";
$pok_mysql_login = "root";
$pok_mysql_pass = "";
$pok_mysql_db = "sema";

$dbconn = mysql_connect($pok_mysql_server,$pok_mysql_login,$pok_mysql_pass);
mysql_select_db($pok_mysql_db);
	
// change id field to idparent
$query = "ALTER TABLE `time_track` CHANGE `id` `id` BIGINT(1) UNSIGNED DEFAULT \"0\" NOT NULL AUTO_INCREMENT";
if (mysql_unbuffered_query($query))
	echo "<b>id</b> successfully changed to <b>idparent</b><br>\n";
// add new id field
$query = "ALTER TABLE `time_track` ADD `idparent` BIGINT(1) UNSIGNED NOT NULL";
if (mysql_unbuffered_query($query))
	echo "added new field <b>id</b><br>\n";
// add new title field
$query = "ALTER TABLE `time_track` ADD `title` VARCHAR(255) DEFAULT \"\"";
if (mysql_unbuffered_query($query))
	echo "added new field <b>title</b><br>\n";
// convert data
$query = "SELECT obj.title, obj.parent_object, tt.id FROM object obj, time_track tt WHERE obj.id=tt.id AND type='5'";
if ($result = mysql_query($query)) {
	echo "data was successfully gotten from DB<br>\n";
	$iKey = 1;
	while ($row = mysql_fetch_object($result)) {
		$query = "UPDATE time_track SET id='$iKey', idparent='$row->parent_object', title='$row->title' WHERE id='$row->id'";
		if (mysql_unbuffered_query($query))
			echo "updated record <b>#$iKey</b> idparent=<b>$row->parent_object</b> title=<b>$row->title</b><br>\n";
		$iKey++;
	}
	// delete all time tracks objects from object table
	$query = "DELETE FROM object WHERE type='5'";
	if (mysql_unbuffered_query($query))
		echo "<b>object</b> table cleared<br>\n";
}
// create timeb_timeb table
$query = "CREATE TABLE `timeb_timeb` (
				  `id` bigint(3) unsigned NOT NULL auto_increment,
				  `idworker` bigint(20) unsigned NOT NULL default '0',
				  `date` date NOT NULL default '0000-00-00',
				  `time` time NOT NULL default '00:00:00',
				  `type` enum('Normal','Ill','Holiday','Shortday') NOT NULL default 'Normal',
				  PRIMARY KEY  (`id`),
				  UNIQUE KEY `id` (`id`),
				  KEY `id_2` (`id`)
				) TYPE=MyISAM;";
if (mysql_unbuffered_query($query))
	echo "table <b>timeb_timeb</b> successfully created<br>\n";

// create timeb_track table
$query = "CREATE TABLE `timeb_track` (
			  `id` bigint(3) unsigned NOT NULL auto_increment,
			  `idworker` bigint(20) unsigned NOT NULL default '0',
			  `date` date NOT NULL default '0000-00-00',
			  `start` time NOT NULL default '00:00:00',
			  `end` time NOT NULL default '00:00:00',
			  `time` int(11) NOT NULL default '0',
			  PRIMARY KEY  (`id`),
			  UNIQUE KEY `id` (`id`),
			  KEY `id_2` (`id`)
			) TYPE=MyISAM;";
if (mysql_unbuffered_query($query))
	echo "table <b>timeb_track</b> successfully created<br>\n";

?>
Return current item: PushOk SEMA