Tuesday, 8 February 2011

PHP script to convert character set for all tables in database


$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'pass';
$dbname = 'db';

header('Content-type: text/plain');

$dbconn = mysql_connect($dbhost, $dbuser, $dbpass) or die( mysql_error() );
$db = mysql_select_db($dbname) or die( mysql_error() );

$sql = 'SHOW TABLES';
$result = mysql_query($sql) or die( mysql_error() );
while ( $row = mysql_fetch_row($result) )
{
$table = mysql_real_escape_string($row[0]);
$sql = "ALTER TABLE $table DEFAULT CHARACTER SET cp1251 COLLATE cp1251_general_ci";
mysql_query($sql) or die( mysql_error() );
print "$table changed to cp1251.\n";
}
mysql_close($dbconn);
?>

Ping does not work

Today I would like to discuss a banal situation: host A is directly connected to host B, ping from host A to host B does not work. What are...