This article describes some of the problems I have encountered in developing my blog and how to solve them. Because this site uses a free remote MySQL database db4free.net, and this database is 5.1 version, so there are many problems in the development process. Therefore, we will publish it for your reference.
I. How to connect a remote database
For PHP to connect to a remote MySQL database, you typically use the following statement:
var $serverName = db4free.net:3306;//Database server
var $dbName = dbname;//database name
var $dbUsername = username;//User Name
var $dbPassword = 123;//Login Password
Mysql_connect ($serverName, $dbUsername, $dbPassword);
mysql_select_db ($dbName);
second, solve the problem of Chinese display garbled
Since MySQL 4.1 introduced multi-language support, but the Chinese inserted in PHP will appear garbled. No matter what code you use. Especially for this 5.1 version of MySQL data, he is more troublesome to use in the Chinese language problem. The workaround is as follows:
1, in the construction of the table when the encoding type is gb2312_chinese_ci.
2, in the PHP page database connection statement plus a line mysql_query ("SET NAMES gb2312", $link); For example
$db _host= "localhost";
$db _user= "root";
$db _password= "Password";
$db _name= "Test";
$link =mysql_connect ($db _host, $db _user, $db _password);
mysql_query ("SET NAMES gb2312", $link);
$db =mysql_select_db ($db _name, $link);
In this way, the Chinese in MySQL can be displayed normally. You can also use the following sentence:
mysql_query ("SET NAMES gb2312");
http://www.bkjia.com/PHPjc/531673.html www.bkjia.com true http://www.bkjia.com/PHPjc/531673.html techarticle This article describes some of the problems I have encountered in developing my blog and how to solve them. Because this site uses a free remote MySQL database db4free.net, and ...