首頁 > 後端開發 > php教程 > PHP录入数据库乱码解决思路

PHP录入数据库乱码解决思路

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-13 13:25:26
原創
942 人瀏覽過

PHP录入数据库乱码
数据库编码是“utf8_bin”字段的编码也是“utf8_bin”,php向数据库录入中文时总是乱码!php文件也用文本编辑并保存为utf-8的了,问题还是没有解决。下面是代码

PHP code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

<!--

 

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

 

-->

 

<?php require_once('../Connections/internal.php'); ?>

<?php if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }

 

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 discuss (a, content) VALUES (%s, %s)",

                       GetSQLValueString($_POST['a'], "text"),

                       GetSQLValueString($_POST['content'], "text"));

 

  mysql_select_db($database_internal, $internal);

  $Result1 = mysql_query($insertSQL, $internal) or die(mysql_error());

}

 

mysql_select_db($database_internal, $internal);

$query_Recordset1 = "SELECT * FROM discuss";

$Recordset1 = mysql_query($query_Recordset1, $internal) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>

 

 

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

<title>discuss</title>

登入後複製
$result1 = mysql_query("SELECT * FROM discuss where id "; } ?>
WHO 在说什么
$a $content $id

选择你的身份

 

相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板