《php---mysql简单应用---在线词典》_PHP教程
[php] view plaincopyprint?
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'];
}
}
}
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]
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 "点击返回
";
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+Ajax实现唯一校验实现代码[简单应用]_PHP教程
-
《php---mysql简单应用---在线词典》_PHP教程
-
php 抽象类的简单应用_PHP教程
-
AJAX技术在PHP开发中的简单应用,ajax技术php开发_PHP教程
-
《php---mysql简单应用---在线词典》
-
AJAX技术在PHP开发中的简单应用_PHP教程
-
AJAX技术在PHP开发中的简单应用,ajax技术php开发_PHP教程
-
PHP函数preg_match_all正则表达式的简单应用_PHP教程
-
《php---mysql简单应用---在线词典》
-
PHP+swoole实现简单多人在线聊天群发,swoole在线聊天_PHP教程