Help with Php and MYSQL

Hi, I’m a beginner webmaster, I installed denwer yesterday and downloaded the php tutorial and I have 2 small questions for you:
1) Why is MYSQL needed?
2) Why, when I write a php file with any encoding (I have already tried all the encodings, it turns out the same) with the code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>  PHP</title>
</head>
<body>
<?php
error_reporting(E_ALL); 
$mydate=date("Y.m.d"); 
echo "<span style='color: red;'>",$mydate,"</span>"; 
echo"<br>", __file__;
?>
</body>
</html>

and when I load it with auto-detection of the encoding, it turns out

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>њѕ№ їµЂІ‹№ PHP</title>
</head>
<body>
<span style='color: red;'>2011.05.19</span><br>Z:\home\rules.ru\www\index.php</body>
</html>

if I set the encoding to utf-8, then the body of the document is corrected, and the title is still the same њѕ№ їµЂІ‹№ PHP
and the browser will even ignore the line

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

Help me fix and what to do and answer why all the same MYSQL?


Answer 1, authority 100%

  1. MySQL – for data storage. The network is full of information with descriptions and examples, so I will not rewrite the entire Internet here. Or ask a more specific question, I will answer.
  2. The fact is that your editor saves text in Windows-1251 format (or any other encoding other than UTF-8). Save the file in UTF-8 encoding and you will be happy.

Answer 2, authority 75%

2. The browser may ignore the encoding from the “Content-Type” meta tag if an encoding has already been passed in the corresponding header. Those. for example, if the following code is saved in UTF-8, then, depending on the browser, it can also produce cracks:

<?php header('Content-Type: text/html; charset=windows-1251', true); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>  PHP</title>
</head>
<body>
  PHP
</body>
</html>

It is possible that Denver is configured to always return Content-Type encoded windows-1251. Accordingly, in this case, you need to either configure Denver to display the correct header, or explicitly pass the header: <?php header('Content-Type: text/html; charset=utf-8', true); ?>


Answer 3, authority 50%

In order for Denver to work in utf-8 encoding, you need the following – in the webserversusrlocalapacheconfhttpd.conffile, find the line AddDefaultCharset. If it is followed by windows-1251, then comment it out and write our own. It should look like this:

#
# Denwer: default charset.
#
#AddDefaultCharset windows-1251
AddDefaultCharset UTF-8

Now restart denver and everything should work fine.

In order for PHP to work with MySQL, UTF-8 encoding is also needed in the file webserversusrlocalmysql5my.cnf

Do like this:

#
#  MySQL-.
#
[mysqld]
#      MySQL 3.x  MySQL 4.0.
old-passwords
#     .
#default-character-set = cp1251
#init-connect = "set names cp1251"
default-character-set = utf8
init-connect = "set names utf8"
skip-character-set-client-handshake

Here we commented out the windows-1251 encoding and included utf-8 instead.


Answer 4

About MySQL.

Try like this:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>  PHP</title>
</head>
<body>
<span style="color:red;">2011.05.19</span><br>
</body>
</html>