php MYSQL数据库连接和乱码现像

数据库连接:

<?php
$conn = @mysql_connect("localhost", "sa", "iamchina") or die("数据库链接错误");
mysql_select_db("filesystem", $conn);
mysql_query("SET NAMES 'UTF8'"); //使用GBK中文编码;
?>
乱码解决:

include("t_conn.php");//数据库连接
mysql_query("set names 'gb2312'");//编码转换

$sqlin="INSERT INTO filesystem.dirtree (ID, parentId, f_name, hint, icon, use_id,Creatime, CreaAddress) VALUES (NULL, '$ssion', '$Dname','', '', '$ssname', '$showtime', '$ipadd')";
mysql_query($sqlin);

或者

include("t_conn.php");//数据库连接
mysql_query("set names 'gb2312'");//编码转换

$sqs="SELECT * FROM f_users where binary user_login='$_POST[username]'and user_pass='$_POST[userpwd]'";
$str=mysql_query($sqs); 
$row1=mysql_fetch_array($str);
switch ($row1)
{
case "": 
  echo "<script>alert('密码或用户名错误!');history.back();</script>";
  break;
default:
/*echo "<script>alert('登录成功!');history.back();</script>";*/
session_start();
$_SESSION["username"]=$username;
echo "<script language=/"javascript/">location.href='fileroject.php';</script>";
}

 

或者

include("t_conn.php");//数据库连接
mysql_query("set names 'gb2312'");
$sqs="SELECT * FROM dirtree";
$str=mysql_query($sqs);
while($row1=mysql_fetch_array($str)){
 $arr[]="{'Id':{$row1[0]},'PId':{$row1[1]},'Name':'{$row1[2]}','url':'{$row1[3]}'}";
}
$stri=implode(',',$arr);//数据集放入数组中,然后进行连接{},{}格式

你可能感兴趣的:(mysql,数据库,PHP,query,insert,include)