《php---mysql简单应用---在线词典》_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了《php---mysql简单应用---在线词典》_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2335字,纯文字阅读大概需要4分钟。
内容图文
![《php---mysql简单应用---在线词典》_PHP教程](/upload/InfoBanner/zyjiaocheng/175/3b0388838442436bb2bee191ab9381dd.jpg)
[php] view plaincopyprint?
<?php
class DicTool{
private $conn;
private $host = "localhost";
private $user = "root";
private $password = "123";
private $db = "test";
//构造函数,初始化数据,连接数据库
function __construct(){
$this->conn = mysql_connect($this->host, $this->user, $this->password);
if (!$this->conn){
die("连接数据库失败".mysql_error());
}
//选择数据库
mysql_select_db($this->db,$this->conn);
mysql_query("set names utf8");
}
function findchword($enword){
$sql = "select * from words where enword ='".$enword."'limit 0,10";
$res = mysql_query($sql,$this->conn) or die(mysql_error());
if (!$res){
return 0;//失败
}else{
$row = mysql_fetch_assoc($res);
return $row['chword'];
}
}
}
<?php
class DicTool{
private $conn;
private $host = "localhost";
private $user = "root";
private $password = "123";
private $db = "test";
//构造函数,初始化数据,连接数据库
function __construct(){
$this->conn = mysql_connect($this->host, $this->user, $this->password);
if (!$this->conn){
die("连接数据库失败".mysql_error());
}
//选择数据库
mysql_select_db($this->db,$this->conn);
mysql_query("set names utf8");
}
function findchword($enword){
$sql = "select * from words where enword ='".$enword."'limit 0,10";
$res = mysql_query($sql,$this->conn) or die(mysql_error());
if (!$res){
return 0;//失败
}else{
$row = mysql_fetch_assoc($res);
return $row['chword'];
}
}
}
[php]
<?php
header("Content-Type: text/html; charset=UTF-8");
include_once 'DicTool.class.php';
$dicTool = new DicTool();
if (isset($_POST['enword'])){
$chword = $dicTool->findchword($_POST['enword']);
if ($chword){
echo $_POST['enword']."对应的中文意思是:".$chword."
";
}else{
echo "未查询到结果!
";
}
}else{
echo "未获取任何输入!
";
}
echo "点击返回
";
<?php
header("Content-Type: text/html; charset=UTF-8");
include_once 'DicTool.class.php';
$dicTool = new DicTool();
if (isset($_POST['enword'])){
$chword = $dicTool->findchword($_POST['enword']);
if ($chword){
echo $_POST['enword']."对应的中文意思是:".$chword."
";
}else{
echo "未查询到结果!
";
}
}else{
echo "未获取任何输入!
";
}
echo "点击返回
";
http://www.bkjia.com/PHPjc/477931.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477931.htmlTechArticle[html] !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=UTF-8 titl...
内容总结
以上是互联网集市为您收集整理的《php---mysql简单应用---在线词典》_PHP教程全部内容,希望文章能够帮你解决《php---mysql简单应用---在线词典》_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。