View Single Post
  #1   IP: 218.2.28.123
Old 2007-08-17, 02:55 AM
topvip topvip is offline
超级版主
 
Join Date: 2006-01-04
Posts: 1206
topvip 正向着好的方向发展
Default Category description length (varchar 255) can increase?

Here is the code:

Quote:
<?php
/************************************************
* INSTALL:

* Place this in your main folder, after you

* run it, please rename it or remove it from

* the site so no one else could use it on your

* database.

*

************************************************/





// Include the initialization info

include('init.php');



// Add a new field

$sql = "ALTER TABLE {$tables['category']['name']} ADD DESC_LONG TEXT NULL AFTER DESCRIPTION";



// If that completed alright, then lets continue on, otherwise DIE DIE DIE!!

if (!$db->Execute($sql))

{

die (mysql_error());

}



// Now, lets grab the DESCRIPTIONS, and input them into the new field

$sql = "SELECT ID, DESCRIPTION FROM {$tables['category']['name']}";



// Pull the results

$data = $db->GetAll($sql);



// Now lets do the ole switch arooo

foreach($data as $row)

{

// Update SQL, it now switches the two DESCRIPTION's around

$db->Execute("UPDATE {$tables['category']['name']} SET DESC_LONG = '" . $row['DESCRIPTION'] . "' WHERE ID = {$row['ID']}");

}



// Now, for the final step we'll rename DESCRIPTION to DESCRIPTION_OLD, and DESC_LONG to DESCRIPTION

$db->Execute("ALTER TABLE {$tables['category']['name']} CHANGE DESCRIPTION DESCRIPTION_OLD VARCHAR( 255 ) NULL DEFAULT NULL") or die (mysql_error());



$db->Execute("ALTER TABLE {$tables['category']['name']} CHANGE DESC_LONG DESCRIPTION TEXT NULL DEFAULT NULL") or die (mysql_error());



echo "All went fine... I guess ; )";



?>
save as description.php, and run it with ie. and deleted it.
Reply With Quote