Home > Backend Development > PHP Tutorial > php为什么插入不了中文,该如何解决

php为什么插入不了中文,该如何解决

WBOY
Release: 2016-06-13 13:38:34
Original
1158 people have browsed it

php为什么插入不了中文
在mysql数据库插入数据的时候,插入英文是没有问题的,但是只要出现中文就不行
  $host = "127.0.0.1";
  $user = "root";
  $pass = "123456";
  $db = "school";
   
  $connection=mysql_connect($host,$user,$pass) or die("Unable to connect!");
  //mysql_select_db($db) or die ("Unable to select database");
  $sqlTest = "create DataBase Person";
  $sql = "insert into employee values(4,'Yund','男',96)";
  if(mysql_db_query("Person",$sql)){
  echo("插入数据成功");
  }
  else{
  echo("插入数据失败");
  }
   
?>
谢谢大家了

------解决方案--------------------
mysql_query("set names 'GBK'");
------解决方案--------------------
脚本编码、数据库编码、数据库操作编码保持一致
------解决方案--------------------
弱弱的问一下“$sql = "insert into employee values(4,'Yund','男',96)";
”能插入吗!!!!
------解决方案--------------------
保持编码一致。楼上的都可以,你可以找个数据库的连接类。直接用类那样就不用这么多问题了,但是最好还是自己写个类然后一直用。不要不明所以

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template