您的位置:首页 > 编程语言 > PHP开发

PHP在线词典项目

2013-12-30 20:48 375 查看







界面设计

<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=gbk">
<title>在线词典</title>
</head>
<body>
<h2>查询英文</h2>
<form
action="wordProcess.php" method="post">
请输入英文:
<input
type="text" name="enword"/>
<input
type="hidden" value="search"
name="type"/>
<input
type="submit" value="查询"/>

</form>
</body>
</html>

数据库设计





wordProcess.php

<?php
require_once
'SqlTool.class.php';
header("Content-type;text/html;charset=utf-8");
//接收英文单词
//isset()如果 变量 存在(非NULL)则返回
TRUE,否则返回 FALSE(包括未定义
if(isset($_REQUEST["enword"])){
$en_word=$_REQUEST["enword"];
}
else {
echo "输入为空";
echo "<a
href=mainView.php>返回重新查询</a>";
}
//看数据库当中有没有这条记录
$sql="select * from words where
enword='".$en_word."'limit 0,1";
$sqlTool=new
SqlTool();
$res=$sqlTool->execute_dql($sql);
if($row=mysql_fetch_row($res)){
echo "$en_word
 对应的中文意思是  
 ".$row[2];
}
else {
echo "没有查询到该词条";
echo "<a
href=mainView.php>返回重新查询</a>";
}
mysql_free_result($res);
?>

SqlTool.class.php

<?php
//数据库的操作方法类
class SqlTool{
private $conn;
private
$host="localhost";
private
$name="root";
private
$password="123456";
private
$dbname="worddb";
function
SqlTool(){
$this->conn=mysql_connect($this->host,$this->name,$this->password);
if(!$this->conn){
die("连接数据库失败".mysql_error());
}
mysql_select_db($this->dbname);
}
//完成查询的方法
function
execute_dql($sql){
$res=mysql_query($sql,$this->conn);
return $res;
}
//完成删除、更新、添加的方法
function
execute_dml($sql){
$b=mysql_query($sql,$this->conn);
if(!$b){
echo
mysql_error();
return 0;//失败
}
else{
if(mysql_affected_rows($this->conn)>0){
return
1;//表示添加或者删除成功,影响了一行以上
}
else{
return
2;//表示没有错误,但是没有影响到行数,例如delete from users where
id=9999如果没有这个id号的话,就会影响0行,但是没有错误
}
}
}
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: