تفضل يالغالي هذا محتوى الملف انسخة واحفظة بأمتداد php
كود PHP:
<?php
/*======================================================================*\
|| #################################################################### ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2006 # ||
|| # # ||
|| # ---------------------------------------------------------------- # ||
|| #################################################################### ||
\*======================================================================*/
// username
$user = 'root';
// password
$pass = '123';
// database
$db = 'db1';
// characterset 'DON NOT USE utf8,ucs2'
$charset = 'latin1';
//------------------------------------------------------------------------
if($_REQUEST['do'] == 'conv'){
@set_time_limit(0);
$link = mysql_connect('localhost', $user, $pass);
mysql_select_db($db, $link);
mysql_query("set character_set_server='$charset'",$link);
mysql_query("set names $charset",$link);
if(isset($_REQUEST['table']))
$curtable = intval($_REQUEST['table']);
else
$curtable = 0;
if(isset($_REQUEST['field']))
$field = intval($_REQUEST['field']);
else
$field = 0;
$tables = array(0 => 1);
$query_id = mysql_query("SHOW tables",$link);
while ($row = mysql_fetch_array($query_id, MYSQL_NUM))
$tables[]= $row[0];
$counts = count($tables)-1;
foreach(array_keys($tables) as $key){
if($key > $curtable){
echo 'Table '.$key.' from '.$counts.'<br><br>';
convert_table_fields_charset($tables[$key], $key, $field, $link);
redirect('c.php?do=conv&table='.$key, 3);
}
}
mysql_query("ALTER DATABASE `$db` DEFAULT CHARACTER SET $charset");
print "Database: $db <b>(converted to $charset)</b>\n";
}else{
print "Before you start you must change <b>user</b> & <b>pass</b> & <b>db</b> variables in this file.<br><br>\n";
print "Ready?<br>\n";
print "<a href='c.php?do=conv'>click here to start</a>\n";
}
/*********************************************************************/
function convert_table_fields_charset($table, $tablekey, $field=0, $link)
{
global $charset;
$tablekey -=1;
$result = mysql_query("SHOW FIELDS FROM $table");
echo '<b>Current table: </b>'.$table.'<br><br>';
$fields = array(0 => 1);
while ($row = mysql_fetch_array($result)){
if(eregi(('set|enum|char|varchar|text|mediumtext|longtext'), $row['Type']))
$fields[] = array($row['Field'], $row['Type'], $row['Default']);
}
$counts = count($fields)-1;
foreach(array_keys($fields) as $key){
if($key > $field){
$f = $fields[$key][0];
$t = $fields[$key][1];
$d = $fields[$key][2];
echo 'Field '.$key.' from '.$counts.'<br><br>';
if(eregi(('char|varchar'), $t)){
$binary = eregi_replace('char|varchar', 'binary', $t);
$default = " NULL DEFAULT '".$d."'";
}
elseif(eregi(('set|enum'), $t)){
$binary = 'blob';
$default = " NULL DEFAULT '".$d."'";
}elseif(eregi(('text'), $t)){
$binary = 'blob';
$default = "";
}
elseif(eregi(('mediumtext'), $t)){
$binary = 'mediumblob';
$default = "";
}
elseif(eregi(('longtext'), $t)){
$binary = 'longblob';
$default = "";
}
mysql_query("ALTER TABLE `$table` CHANGE $f $f $binary");
mysql_query("ALTER TABLE `$table` CHANGE $f $f $t CHARACTER SET $charset$default");
echo '<b>Field: </b>'.$f . ' ' . $t." <i>(converted to $charset)</i><br>";
redirect('c.php?do=conv&table='.$tablekey.'&field='.$key, 2);
}
}
mysql_query("ALTER TABLE `$table` DEFAULT CHARACTER SET $charset");
echo '<br><b>Table: </b>'.$table." <i>(converted to $charset)</i>";
}
/*********************************************************************/
function redirect($gotopage, $timeout = 0)
{
echo '<p align="center" class="smallfont"><a href="' . $gotopage . '" onclick="javascript:clearTimeout(timerID);">processing complete proceed</a></p>';
echo "\n<script type=\"text/javascript\">\n";
if ($timeout == 0)
{
echo "window.location=\"$gotopage\";";
}
else
{
echo "myvar = \"\"; timeout = " . ($timeout*10) . ";
function exec_refresh()
{
window.status=\"redirecting\"+myvar; myvar = myvar + \" .\";
timerID = setTimeout(\"exec_refresh();\", 100);
if (timeout > 0)
{ timeout -= 1; }
else { clearTimeout(timerID); window.status=\"\"; window.location=\"$gotopage\"; }
}
exec_refresh();";
}
echo "\n</script>\n";
exit;
}
?>
مواقع النشر (المفضلة)