当前位置: 编程技术>php
本页文章导读:
▪Linux下进行MYSQL编程时插入中文乱码的解决方案
插入中文是乱码,尝试了许多方法,比如我先把vim里设置为:set fileencoding=utf-8不起作用,后来想想也对,和vim没什么关系 然后就尝试c#代码,用Encoding.UTF8.GetString()方法,后来也不对。 我就.........
▪mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法
mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法
shell> mysql
Client does not support authentication protocol requested
by server; consider upgrading MySQL client
.........
▪一个简单的PHP&MYSQL留言板源码第1/2页
初学PHP,花了几晚上写了个留言板,请高手指正 p.s.我的空间不支持PHP,不能提供演示了T_T 数据库结构:(库名:lyb) 表一: admin 字段: id(int11) name(varchvr) password(varchvr) 表二: lo 字段:.........
[1]Linux下进行MYSQL编程时插入中文乱码的解决方案
来源: 互联网 发布时间: 2013-11-30
插入中文是乱码,尝试了许多方法,比如我先把vim里设置为:set fileencoding=utf-8不起作用,后来想想也对,和vim没什么关系
然后就尝试c#代码,用Encoding.UTF8.GetString()方法,后来也不对。
我就郁闷了,忽然想起来莫不是mysql的设置问题???
于是,sudo nano /etc/mysql/my.cnf
插入下面红色代码,default-character-set = utf8,成功,不乱码了~~~根本不用什么Encoding.....
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
default-character-set = utf8
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/english
skip-external-locking
然后就尝试c#代码,用Encoding.UTF8.GetString()方法,后来也不对。
我就郁闷了,忽然想起来莫不是mysql的设置问题???
于是,sudo nano /etc/mysql/my.cnf
插入下面红色代码,default-character-set = utf8,成功,不乱码了~~~根本不用什么Encoding.....
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
default-character-set = utf8
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/english
skip-external-locking
[2]mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法
来源: 互联网 发布时间: 2013-11-30
mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法
shell> mysql
Client does not support authentication protocol requested
by server; consider upgrading MySQL client
官方的说法是
MySQL 4.1 and up uses an authentication protocol based on a password hashing algorithm that is incompatible with that used by older clients. .....
如果你升级mysql到4.1以上版本后遇到以上问题,请先确定你的mysql client 是4.1或者更高版本.(WINDOWS下有问题你就直接跳到下面看解决方法了,因为MYSQL 在WINDOWS是client和server一起装上了的)
请使用以下两种方法之一
其一:
mysql> SET PASSWORD FOR
-> 'some_user'@'some_host' = OLD_PASSWORD('newpwd');
其二:
mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('newpwd')
-> WHERE Host = 'some_host' AND User = 'some_user';
mysql> FLUSH PRIVILEGES;
上面红色的部分请按自己实际情况修改....
这样做后,连接就会正常了@!
shell> mysql
Client does not support authentication protocol requested
by server; consider upgrading MySQL client
官方的说法是
MySQL 4.1 and up uses an authentication protocol based on a password hashing algorithm that is incompatible with that used by older clients. .....
如果你升级mysql到4.1以上版本后遇到以上问题,请先确定你的mysql client 是4.1或者更高版本.(WINDOWS下有问题你就直接跳到下面看解决方法了,因为MYSQL 在WINDOWS是client和server一起装上了的)
请使用以下两种方法之一
其一:
mysql> SET PASSWORD FOR
-> 'some_user'@'some_host' = OLD_PASSWORD('newpwd');
其二:
mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('newpwd')
-> WHERE Host = 'some_host' AND User = 'some_user';
mysql> FLUSH PRIVILEGES;
上面红色的部分请按自己实际情况修改....
这样做后,连接就会正常了@!
[3]一个简单的PHP&MYSQL留言板源码第1/2页
来源: 互联网 发布时间: 2013-11-30
初学PHP,花了几晚上写了个留言板,请高手指正
p.s.我的空间不支持PHP,不能提供演示了T_T
数据库结构:(库名:lyb)
表一: admin
字段: id(int11) name(varchvr) password(varchvr)
表二: lo
字段: id(int11) username(varchvr) sex(varchvr) qq(varchvr) email(varchvr) info(text) ip(varchvr) submit_time(datetime)
1 conn.php(连接数据库文件)
<?php
mysql_connect("localhost","root","");//连接数据库
mysql_select_db("lyb");//选择数据库
?>
2 header.php(公用头部文件)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>银子留言板 Version 1.0</title>
</head>
<link href="/blog_article/css.css" rel="stylesheet" type="text/css" />
<body>
<?php session_start(); ?>
<div id="head">
<div id="head_l">
<ul>
<li><a href="/blog_article/index.html">偶要看留言</a></li>
<li><a href="/blog_article/post.html">偶要发表</a></li>
<?php
//session_start();//DOFY同学指出本句前不能有任何输出内容,就此改正
if($_SESSION["key"]==1){//如果获取的SESSION为1则显示管理项
?>
<li><a href="/blog_article/adminexit.html">退出管理</a></li>
<?
}
else
{
?>
<li><a href="/blog_article/admin.html">偶要管理</a></li>
<?}?>
</ul>
</div>
<div id="head_r">银子留言板 Version 1.0</div>
</div>
3 footer.php(公用底部文件)
<?php
$counterFile="conter.xml";
function displayCounter($counterFile){
$fp = fopen($counterFile,"rw");
$num = fgets($fp,5);
$num += 1;
print "<div id=\"footer\">银子留言板 Version 1.0 您是第 "."$num"." 位无聊的银</div>";
exec("rm -rf $counterFile");
exec("echo $num > $counterFile");
}
if(!file_exists($counterFile)){
exec("echo 0 > $counterFile");
}
displayCounter($counterFile);
?>
</body>
</html>
4 index.php(首页)
<?php
require_once("conn.php");
require_once("header.php");
session_start();
//分页代码开始
$pagesize = 10;//设置每页显示条数
$rs = mysql_query("select count(*) from lo");//取得记录总数,计算总页数用
$myrow = mysql_fetch_array($rs);
$numrows = $myrow[0];//计算总记录
$pages = intval($numrows/$pagesize);
if($numrows%$pagesize)$pages++;//设置页数
if(isset($_GET['page']))
{
$page = intval($_GET['page']);
}
else
{
$page = 1;//设为第一页
}
$offset = $pagesize*($page-1);//计算记录偏移量
//分页代码结束
$sql = "select id,username,sex,qq,email,info,ip,DATE_FORMAT(submit_time, '%Y年%m月%d日 %T' ) from lo order by id desc limit $offset,$pagesize";//用到了DATE-FORMAT格式化日期格式
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if($num>0){
while($row = mysql_fetch_array($result))
{
//echo print_r($row);
if($row[2]=="男")//这个使性别改成你想要的名称^_^
{
$sex = "帅锅";
}
else
{
$sex = "美女";
}
?>
<div id="show">
<p >第 [<?= $row[0] ?>] 条留言<p>
<p >留言人:<span ><?= $row[1]?></span> 性别:<?= $sex ?> 留言时间:<?= $row[7] ?> <? if($row[3]) {?> <a href="http://wpa.qq.com/msgrd?V=1&Uin=<?= $row[3] ?>&Site=http://www.loai.cn&Menu=yes"><img src="/blog_article/img/qq.gif" alt="<?= $row[3]?>" /></a><? } ?><? if($row[4]){ ?> <a href="mailto:<?= $row[4] ?>"><img src="/blog_article/img/email.gif" alt="<?= $row[4]?>" /></a> <? }?><? if($_SESSION["key"]==1){ ?> IP:<?= $row[6] ?> <a href="/blog_article/update/wuleying/amp;id/lt;/ $row[0]/gt;.html">更改</a> <a href="/blog_article/delete/wuleying/amp;id/lt;/ $row[0]/gt;.html">删除</a><?}?></a></p>
<p >留言内容:</p>
<div id="show_info"><?= nl2br(htmlspecialchars($row[5])) ?></div>
</div>
<?php
}
}
else
{
echo "<div id=\"show\">无数据......</div>";
}
?>
<div id="show_page">
<p>
<?php
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if($page==1&&$pages>1)
{
echo "首页 | ";
echo "上一页 | ";
echo "<a href=/index.html"index.php?page=".$next."\">下一页</a> | ";
echo "<a href=/index.html"index.php?page=".$last."\">尾页</a> | ";
}
elseif($page>=1&&$page!=$pages&&$num>0)
{
echo "<a href=/index.html"index.php?page=".$first."\">首页</a> | ";
echo "<a href=/index.html"index.php?page=".$prev."\">上一页</a> | ";
echo "<a href=/index.html"index.php?page=".$next."\">下一页</a> | ";
echo "<a href=/index.html"index.php?page=".$last."\">尾页</a> | ";
}
elseif($page==$pages&&$page!=1)
{
echo "<a href=/index.html"index.php?page=".$first."\">首页</a> | ";
echo "<a href=/index.html"index.php?page=".$prev."\">上一页</a> | ";
echo "下一页 | ";
echo "尾页 | ";
}
elseif($page==$pages)
{
echo "首页 | ";
echo "上一页 | ";
echo "下一页 | ";
echo "尾页 | ";
}
else
{
echo "首页 | ";
echo "上一页 | ";
echo "下一页 | ";
echo "尾页 | ";
}
?>
共 <span><?= $pages ?></span> 页 | 当前第 <span><?= $page ?></span> 页 | 共 <span><?=$numrows ?></span> 条留言</p>
</div>
<?php
mysql_close();
?>
<?php
require_once("footer.php");
?>
p.s.我的空间不支持PHP,不能提供演示了T_T
数据库结构:(库名:lyb)
表一: admin
字段: id(int11) name(varchvr) password(varchvr)
表二: lo
字段: id(int11) username(varchvr) sex(varchvr) qq(varchvr) email(varchvr) info(text) ip(varchvr) submit_time(datetime)
1 conn.php(连接数据库文件)
<?php
mysql_connect("localhost","root","");//连接数据库
mysql_select_db("lyb");//选择数据库
?>
2 header.php(公用头部文件)
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>银子留言板 Version 1.0</title>
</head>
<link href="/blog_article/css.css" rel="stylesheet" type="text/css" />
<body>
<?php session_start(); ?>
<div id="head">
<div id="head_l">
<ul>
<li><a href="/blog_article/index.html">偶要看留言</a></li>
<li><a href="/blog_article/post.html">偶要发表</a></li>
<?php
//session_start();//DOFY同学指出本句前不能有任何输出内容,就此改正
if($_SESSION["key"]==1){//如果获取的SESSION为1则显示管理项
?>
<li><a href="/blog_article/adminexit.html">退出管理</a></li>
<?
}
else
{
?>
<li><a href="/blog_article/admin.html">偶要管理</a></li>
<?}?>
</ul>
</div>
<div id="head_r">银子留言板 Version 1.0</div>
</div>
3 footer.php(公用底部文件)
代码如下:
<?php
$counterFile="conter.xml";
function displayCounter($counterFile){
$fp = fopen($counterFile,"rw");
$num = fgets($fp,5);
$num += 1;
print "<div id=\"footer\">银子留言板 Version 1.0 您是第 "."$num"." 位无聊的银</div>";
exec("rm -rf $counterFile");
exec("echo $num > $counterFile");
}
if(!file_exists($counterFile)){
exec("echo 0 > $counterFile");
}
displayCounter($counterFile);
?>
</body>
</html>
4 index.php(首页)
代码如下:
<?php
require_once("conn.php");
require_once("header.php");
session_start();
//分页代码开始
$pagesize = 10;//设置每页显示条数
$rs = mysql_query("select count(*) from lo");//取得记录总数,计算总页数用
$myrow = mysql_fetch_array($rs);
$numrows = $myrow[0];//计算总记录
$pages = intval($numrows/$pagesize);
if($numrows%$pagesize)$pages++;//设置页数
if(isset($_GET['page']))
{
$page = intval($_GET['page']);
}
else
{
$page = 1;//设为第一页
}
$offset = $pagesize*($page-1);//计算记录偏移量
//分页代码结束
$sql = "select id,username,sex,qq,email,info,ip,DATE_FORMAT(submit_time, '%Y年%m月%d日 %T' ) from lo order by id desc limit $offset,$pagesize";//用到了DATE-FORMAT格式化日期格式
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if($num>0){
while($row = mysql_fetch_array($result))
{
//echo print_r($row);
if($row[2]=="男")//这个使性别改成你想要的名称^_^
{
$sex = "帅锅";
}
else
{
$sex = "美女";
}
?>
<div id="show">
<p >第 [<?= $row[0] ?>] 条留言<p>
<p >留言人:<span ><?= $row[1]?></span> 性别:<?= $sex ?> 留言时间:<?= $row[7] ?> <? if($row[3]) {?> <a href="http://wpa.qq.com/msgrd?V=1&Uin=<?= $row[3] ?>&Site=http://www.loai.cn&Menu=yes"><img src="/blog_article/img/qq.gif" alt="<?= $row[3]?>" /></a><? } ?><? if($row[4]){ ?> <a href="mailto:<?= $row[4] ?>"><img src="/blog_article/img/email.gif" alt="<?= $row[4]?>" /></a> <? }?><? if($_SESSION["key"]==1){ ?> IP:<?= $row[6] ?> <a href="/blog_article/update/wuleying/amp;id/lt;/ $row[0]/gt;.html">更改</a> <a href="/blog_article/delete/wuleying/amp;id/lt;/ $row[0]/gt;.html">删除</a><?}?></a></p>
<p >留言内容:</p>
<div id="show_info"><?= nl2br(htmlspecialchars($row[5])) ?></div>
</div>
<?php
}
}
else
{
echo "<div id=\"show\">无数据......</div>";
}
?>
<div id="show_page">
<p>
<?php
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if($page==1&&$pages>1)
{
echo "首页 | ";
echo "上一页 | ";
echo "<a href=/index.html"index.php?page=".$next."\">下一页</a> | ";
echo "<a href=/index.html"index.php?page=".$last."\">尾页</a> | ";
}
elseif($page>=1&&$page!=$pages&&$num>0)
{
echo "<a href=/index.html"index.php?page=".$first."\">首页</a> | ";
echo "<a href=/index.html"index.php?page=".$prev."\">上一页</a> | ";
echo "<a href=/index.html"index.php?page=".$next."\">下一页</a> | ";
echo "<a href=/index.html"index.php?page=".$last."\">尾页</a> | ";
}
elseif($page==$pages&&$page!=1)
{
echo "<a href=/index.html"index.php?page=".$first."\">首页</a> | ";
echo "<a href=/index.html"index.php?page=".$prev."\">上一页</a> | ";
echo "下一页 | ";
echo "尾页 | ";
}
elseif($page==$pages)
{
echo "首页 | ";
echo "上一页 | ";
echo "下一页 | ";
echo "尾页 | ";
}
else
{
echo "首页 | ";
echo "上一页 | ";
echo "下一页 | ";
echo "尾页 | ";
}
?>
共 <span><?= $pages ?></span> 页 | 当前第 <span><?= $page ?></span> 页 | 共 <span><?=$numrows ?></span> 条留言</p>
</div>
<?php
mysql_close();
?>
<?php
require_once("footer.php");
?>
最新技术文章: