BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / database / #1788同步于 2008/1/6
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Database机器人发帖

mysql和php连接的一个问题~

zjai
2008/1/6镜像同步14 回复
为什么直接导入中文数据到Mysql就可以,但从php导入到mysql就不行,而且从mysql导出中文到php也只能显示成?符号,英文和数字都没有问题 向达人求教~~~
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
zjai机器人#1 · 2008/1/6
对了,我的mysql默认的编码是gbk~
coolfantasy机器人#2 · 2008/1/6
$sql = "SET NAMES GBK"; mysql_query($sql);
zjai机器人#3 · 2008/1/6
尝试过了,而且查看mysql的几个默认编码方式例如client,connect等都是gbk了,但好像没有起到作用似的.... 【 在 coolfantasy 的大作中提到: 】 : $sql = "SET NAMES GBK"; : mysql_query($sql);
zjai机器人#4 · 2008/1/6
感觉是php那块出了问题,但又不知道问题出在哪...
coolfantasy机器人#5 · 2008/1/6
换IE试试 调整页面编码为GB2312
zjai机器人#6 · 2008/1/6
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 这是页面的属性 只要是中文,根本就不能导入数据库,连乱码都没有
coolfantasy机器人#7 · 2008/1/6
贴代码
zjai机器人#8 · 2008/1/6
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>注册</title> <style type="text/css"> <!-- @import url("css/注册.css"); --> </style> </head> <body> <?php $id=$_POST['id']; $password=$_POST['password']; $passwordagain=$_POST['passwordagain']; $emailfpw=$_POST['emailfpw']; $questionfpw=$_POST['questionfpw']; $anwserfpw=$_POST['anwserfpw']; $name=$_POST['name']; $birthyear=$_POST['birthyear']; $birthmonth=$_POST['birthmonth']; $birthdate=$_POST['birthdate']; $gender=$_POST['gender']; $qualification=$_POST['qualification']; $posts=$_POST['posts']; $company=$_POST['company']; $province=$_POST['province']; $city=$_POST['city']; $phone=$_POST['phone']; $email=$_POST['email']; $updatefile=$_POST['updatefile']; $checknum=$_POST['checknum']; /* if (!$id || !$password || !$passwordagain ||!$emailfpw || !$questionfpw || !$anwserfpw || !$name || !$gender || !$birthyear || !$birthmonth || !$birthdate || !$qualification || !$posts || !$company || !$province || !$city || !$phone || !$email || !$updatefile || !$checknum) { echo 'you have not entered all details'; exit; } if ($password !=$passwordagain) { echo 'password error'; exit; } if ($checknum != $_POST['authnum']) { echo 'checknum wrong'; exit; } /*if (!get_magic_quotes_gpc()) { $id=addslashed($id); $password=addslashed($password); }*/ $ii='张晶'; echo $ii; @ $db=new mysqli('localhost','root','13578108','test'); if (mysqli_connect_errno()) { echo 'Error:Could not connect to database'; exit; } $sql = "SET NAMES GBK"; mysql_query($sql); $query="insert into test values ('$id','$ii')"; $result=$db->query($query); /* $query="insert into login values ('$id',sha1('$password'),'$emailfpw','$questionfpw','$anwserfpw')"; $result=$db->query($query); $sql = "SET NAMES GBK"; mysql_query($sql); $query="insert into personalinf values ('$id','$name','$birthyear','$birthmonth','$birthdate','1','1','1','1','1','1','1','1','1')";//('$id','$name','$birthyear','$birthmonth','$birthdate','gender','$qualification','$posts','$company','$province','$city','$phone','$email','$updatefile')"; $result=$db->query($query);*/ if ($result) echo successful; /*$db->close();*/ ?>
coolfantasy机器人#9 · 2008/1/6
【 在 zjai (笑书~~≮雪域≯之雪书) 的大作中提到: 】 : 标 题: Re: mysql和php连接的一个问题~ : 发信站: 北邮人论坛 (Sun Jan 6 15:24:53 2008), 站内 : : <head> : <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> : <title>注册</title> : <style type="text/css"> : <!-- : @import url("css/注册.css"); : --> : </style> : </head> : : <body> : <?php : $id=$_POST['id']; : $password=$_POST['password']; : $passwordagain=$_POST['passwordagain']; : $emailfpw=$_POST['emailfpw']; : $questionfpw=$_POST['questionfpw']; : $anwserfpw=$_POST['anwserfpw']; : $name=$_POST['name']; : $birthyear=$_POST['birthyear']; : $birthmonth=$_POST['birthmonth']; : $birthdate=$_POST['birthdate']; : $gender=$_POST['gender']; : $qualification=$_POST['qualification']; : $posts=$_POST['posts']; : $company=$_POST['company']; : $province=$_POST['province']; : $city=$_POST['city']; : $phone=$_POST['phone']; : $email=$_POST['email']; : $updatefile=$_POST['updatefile']; : $checknum=$_POST['checknum']; : /* if (!$id || !$password || !$passwordagain ||!$emailfpw || !$questionfpw || !$anwserfpw || !$name || !$gender || !$birthyear || !$birthmonth || !$birthdate || !$qualification || !$posts || !$company || !$province || !$city || !$phone || !$email || !$updatefile || !$checknum) : { : echo 'you have not entered all details'; : exit; : } : if ($password !=$passwordagain) : { : echo 'password error'; : exit; : } : if ($checknum != $_POST['authnum']) : { : echo 'checknum wrong'; : exit; : } : : /*if (!get_magic_quotes_gpc()) : { : $id=addslashed($id); : $password=addslashed($password); : }*/ : $ii='张晶'; : echo $ii; : @ $db=new mysqli('localhost','root','13578108','test'); : if (mysqli_connect_errno()) : { : echo 'Error:Could not connect to database'; : exit; : } : $sql = "SET NAMES GBK"; : mysql_query($sql); : $query="insert into test values ('$id','$ii')"; : $result=$db->query($query); : /* $query="insert into login values ('$id',sha1('$password'),'$emailfpw','$questionfpw','$anwserfpw')"; : $result=$db->query($query); : $sql = "SET NAMES GBK"; : mysql_query($sql); //改成 $db->query($sql); //试试 : $query="insert into personalinf values ('$id','$name','$birthyear','$birthmonth','$birthdate','1','1','1','1','1','1','1','1','1')";//('$id','$name','$birthyear','$birthmonth','$birthdate','gender','$qualification','$posts','$company','$province','$city','$phone','$email','$updatefile')"; : $result=$db->query($query);*/ : if ($result) : echo successful; : /*$db->close();*/ : ?> : -- : 从Royal到ro_AL,从cs到dota,从大二到大三,就快完了,就快说gg了~~~ : : 这无涯的一场生啊...... : : "你是谁?我喜欢你!" : : ※ 来源:·北邮人论坛 http://forum.byr.edu.cn·[FROM: 59.64.199.*]