'php---mysql simple application---online dictionary'_PHP tutorial

WBOY
Release: 2016-07-14 10:06:45
Original
914 people have browsed it

[html]
 
 
 
 
Insert title here 
 
 
   

 
        请输入您要查找的英文单词:
 
       
 
       
 
   
 
 
 





Insert title here


 


  请输入您要查找的英文单词:

  

  

 


[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";

//Constructor, initialize data, connect to database
function __construct(){
 
$this->conn = mysql_connect($this->host, $this->user, $this->password);
if (!$this->conn){
Die("Failed to connect to database".mysql_error());
}
//Select database
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;//Failed
}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']."The corresponding Chinese meaning is: ".$chword."
";
         }else{
echo "No results found!
";
         } 
}else{
echo "No input obtained!
";
}  
echo "Click to return
";

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']."The corresponding Chinese meaning is: ".$chword."
";
}else{
echo "No results found!
";
}
}else{
echo "No input obtained!
";
}
echo "
Click to return
";


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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template