首先我的mysql
mysql> show variables like '%char% ';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.1\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.02 sec)在mysql和mysqladmin中数据均显出是乱码。
我的数据是用dreamweaver8设计的网页表单输入的。
index.php网页如下:
<?php require_once('Connections/query.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO patient_base (patient_id, name, sex, age, `work`, birthplace, nation, allergichistory, address, phonecode1, phonecode2) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['patient_id'], "text"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['sex'], "text"),
GetSQLValueString($_POST['age'], "int"),
GetSQLValueString($_POST['work'], "text"),
GetSQLValueString($_POST['birthplace'], "text"),
GetSQLValueString($_POST['nation'], "text"),
GetSQLValueString($_POST['allergichistory'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['phonecode1'], "text"),
GetSQLValueString($_POST['phonecode2'], "text")); mysql_select_db($database_query, $query);
$Result1 = mysql_query($insertSQL, $query) or die(mysql_error());
}mysql_select_db($database_query, $query);
$query_getquery = "SELECT * FROM patient_base";
$getquery = mysql_query($query_getquery, $query) or die(mysql_error());
$row_getquery = mysql_fetch_assoc($getquery);
$totalRows_getquery = mysql_num_rows($getquery);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<form method="POST" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Patient_id:</td>
<td><input type="text" name="patient_id" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Name:</td>
<td><input type="text" name="name" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Sex:</td>
<td><input type="text" name="sex" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Age:</td>
<td><input type="text" name="age" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Work:</td>
<td><input type="text" name="work" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Birthplace:</td>
<td><input type="text" name="birthplace" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Nation:</td>
<td><input type="text" name="nation" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Allergichistory:</td>
<td><input type="text" name="allergichistory" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Address:</td>
<td><input type="text" name="address" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Phonecode1:</td>
<td><input type="text" name="phonecode1" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Phonecode2:</td>
<td><input type="text" name="phonecode2" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="插入记录"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($getquery);
?>
query.php文件如下:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_query = "localhost";
$database_query = "dentinfo";
$username_query = "root";
$password_query = "46539364";
$query = mysql_pconnect($hostname_query, $username_query, $password_query) or trigger_error(mysql_error(),E_USER_ERROR);
?>以上就是全部!
数据能在网页中正确显示!
在mysql和mysqladmin中数据均显出是乱码。
mysql> show variables like '%char% ';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.1\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.02 sec)在mysql和mysqladmin中数据均显出是乱码。
我的数据是用dreamweaver8设计的网页表单输入的。
index.php网页如下:
<?php require_once('Connections/query.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO patient_base (patient_id, name, sex, age, `work`, birthplace, nation, allergichistory, address, phonecode1, phonecode2) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['patient_id'], "text"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['sex'], "text"),
GetSQLValueString($_POST['age'], "int"),
GetSQLValueString($_POST['work'], "text"),
GetSQLValueString($_POST['birthplace'], "text"),
GetSQLValueString($_POST['nation'], "text"),
GetSQLValueString($_POST['allergichistory'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['phonecode1'], "text"),
GetSQLValueString($_POST['phonecode2'], "text")); mysql_select_db($database_query, $query);
$Result1 = mysql_query($insertSQL, $query) or die(mysql_error());
}mysql_select_db($database_query, $query);
$query_getquery = "SELECT * FROM patient_base";
$getquery = mysql_query($query_getquery, $query) or die(mysql_error());
$row_getquery = mysql_fetch_assoc($getquery);
$totalRows_getquery = mysql_num_rows($getquery);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<form method="POST" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Patient_id:</td>
<td><input type="text" name="patient_id" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Name:</td>
<td><input type="text" name="name" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Sex:</td>
<td><input type="text" name="sex" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Age:</td>
<td><input type="text" name="age" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Work:</td>
<td><input type="text" name="work" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Birthplace:</td>
<td><input type="text" name="birthplace" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Nation:</td>
<td><input type="text" name="nation" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Allergichistory:</td>
<td><input type="text" name="allergichistory" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Address:</td>
<td><input type="text" name="address" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Phonecode1:</td>
<td><input type="text" name="phonecode1" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Phonecode2:</td>
<td><input type="text" name="phonecode2" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="插入记录"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($getquery);
?>
query.php文件如下:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_query = "localhost";
$database_query = "dentinfo";
$username_query = "root";
$password_query = "46539364";
$query = mysql_pconnect($hostname_query, $username_query, $password_query) or trigger_error(mysql_error(),E_USER_ERROR);
?>以上就是全部!
数据能在网页中正确显示!
在mysql和mysqladmin中数据均显出是乱码。
HTTP Headers Information
HTTP Request Headers
HTTP Request GET / HTTP/1.1
Accept image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, */*
Accept-Language zh-cn
UA-CPU x86
Accept-Encoding gzip, deflate
User-Agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; CIBA)
Host 172.16.0.128
Connection Keep-Alive
HTTP Response Headers
X-Powered-By PHP/5.2.6
Keep-Alive timeout=15, max=100
Connection Keep-Alive
Transfer-Encoding chunked
Content-Type text/html; charset=utf-8
iconv
iconv support enabled
iconv implementation "libiconv"
iconv library version 1.11 Directive Local Value Master Value
iconv.input_encoding utf8 utf8
iconv.internal_encoding utf8 utf8
iconv.output_encoding utf8 utf8