04-線上小詞典案例

來源:互聯網
上載者:User

myView.php

<html><head><title>線上詞典</title><meta http-equiv="content-type" content="text/html;charset=utf-8"/></head><h1>查詢英文</h1><form action="wordProcess.php" method="post">請輸入英文:<input type="text" name="enword"/><input type="hidden" value="search" name="type"/><input type="submit" value="查詢"/></form></html>

wordProcess.php

<?php    require_once "mysqltool.php";header("Content-type:text/html;charset=utf-8");   //接收英文單詞   if(isset($_POST['enword'])){       $en_word=$_POST['enword'];   }else{       echo "輸入為空白!";   echo "<br/><a href='myView.php'>返回重新查詢</a>";   }      //看看資料庫中有沒有這條記錄    $sql="select chword from words where enword='".$en_word."' limit 0,1" ;//設計表/* create database worddb;create table words( id int primary key auto_increment, enword varchar(32) not null, chword varchar(256) not null      ); insert into words(enword,chword)values('boy','男孩'); insert into words(enword,chword)values('school','學校');*///查詢(物件導向)$sqlTool=new SqlTool();$res=$sqlTool->execute_dql($sql);if($row=mysql_fetch_assoc($res)){   echo $en_word."對應的中文意思是==".$row['chword'];    echo "<br/><a href='mainView.php'>返回重新查詢</a>";}else{    echo "沒有查詢到。。。";echo "<br/><a href='mainView.php'>返回重新查詢</a>";}mysql_free_result($res);?>

mysqltool.php

<?php   class SqlTool{     private $conn; private $host="localhost";     private $user="root"; private $password="root";     private $db="worddb"; function SqlTool(){   $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"); } //完成select語句 function  execute_dql($sql){ $res=mysql_query($sql) or die(mysql_error()); return $res; } //完成update delete insert操作 function  execute_dml($sql){ //返回的是一個布爾值   $b=mysql_query($sql,$this->conn) or die(mysql_error());   if(!$b){      return 0;//0表示失敗   }else{      if(mysql_affected_rows($this->conn)>0){   return 1;//表示真的成功  }else{    return 2;//表示沒有行數影響  }   } }   }?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.