Maison > Article > développement back-end > 留言板问题求助
先问一个关于乱码的问题,
在my.ini中设置了 [client] default-character-set=utf8 [mysqld] default-character-set=utf8 然后重启wamp,phpmyadmin就连接不上了,就是#2002 那个套接字错误提示,然后我就把my.ini刚做的修改又改了回去,还是连接不上,(我把修改撤销了应该可以了呀?? 问题1)最后把localhost改为127.0.0.1 才恢复正常
问题二: 上述操作之后
最后问题
1、conn文件
<?php $conn = mysql_connect("localhost","root","") or die("Can't connect database: ".mysql_error());if($conn) echo "链接成功!"; mysql_select_db("liuyan"); mysql_query("set names 'gbk'");?>
<form name = "msgform" method = "post" action = "write.php" enctype = "multipart/form-data" onsubmit = "return checkMessage()">//javascript略去了<table width = "64%" border = "0" cellspacing = "1" cellpadding = "3" bgcolor = "#66CCFF" align = "center"><tr><td width = "48%">用 户: <input type = "txet" name = "username"></td> </tr> <tr><td colspan = "2">标 题:<input type = "text" name = "title" size = "60" maxlength = "50"></td></tr><tr><td colspan = "2"><textarea name = "content" rows = "10" cols = "100"></textarea></td></tr><tr><td><div align = "right"><input type = "submit" name = "sub" value = "提交"></div></td><td><input type = "reset" name = "Rewrite" value = "重写"></td></tr> </table></form>
<?phpinclude("conn.php");if(isset($_POST['username'])){ $username = $_POST['username']; $title = $_POST['title']; $content = $_POST['content']; $sql = "insert into easy values('$username','$title','$content',now())"; mysql_query($sql) or die("插入失败: ".mysql_error());}?><?phpinclude("conn.php"); $rowsPerPage = 10; $row = mysql_fetch_array(mysql_query("select count (*) as c from easy")); //查询总记录数...这点书上看的,不太懂,求解释 $rows = $row['c']; //得到记录数 /* $a = "select * from easy"; $b = mysql_query($a); $rows = mysql_num_rows($b);这个可以么? 另外这个和上面那个有什么区别?? */ $pages = ceil($rows/$rowsPerPage); //计算页数 $curPage = 1; if(isset($_REQUEST['curPage'])) $curPage = $_REQUEST['curPage']; $sql = "select * from easy order by posttime" ." limit ".($curPage - 1) * $rowsPerPage." ,$rowsPerPage"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<table width = 90% align=center cellpadding=5 cellspacing=1 bgcolor=blue>"; echo "<tr>"; echo "<td rowspan = 2 width = 25% bgcolor = white>"; echo "<tr>标题:<?=$row[title]?></tr>"; echo "<li>用户:<?=$row[username]?>"; echo "<li> <?= $row[posttime]?>"; echo "</td>"; echo "<td>内容:<?= $row[content]?></td>"; echo "</tr>"; echo "</table>"; echo "<br>"; } //分页链接 echo "<div align = center>"; for($i = 1;$i<$pages;$i++) echo "<a href = 'write.php?curPage = $i'>$i</a>$nbsp; "; echo "</div>";?>
mysql_query("select count (*) as c from easy") or die(mysql_error()); //这样报什么错
1、在未知后果的情况下,不要随意改变配置信息
2、数据库服务是公共的,任何的总体配置的改变,必然会影响到其他应用的使用
3、任何配置信息的改变,都只会影响改变时刻以后的表现。而改变时刻之前保存的数据有可能会出问题
4、有人说用 ALTER 改变字符集时,可以同时对内容的字符集做转换处理。但至少在我用的 mysql 中是不可以的
建议你恢复原始的配置文件,这样才有利于问题的解决
设置字段的字符集和适时的使用 set names 指令,是正确的做法
因为你的项目很可能会运行在一个已有的环境中。如程序依赖外部配置,那么后果是可想而知的