查詢前台頁面(enword.php)
英漢詞典
2.編寫資料庫操作類(ewTool.class.php)
conn=mysql_connect($this->host,$this->user,$this->password) or die("連結失敗"); mysql_select_db($this->bd); mysql_query("set names utf8"); } //查詢資料庫語句 public function dql($sql) { //$res為資源型 $res=mysql_query($sql,$this->conn) or die(mysql_error()); return $res; } //添加資料庫語句 public function dml($sql) { $b=mysql_query($sql,$this->conn); if(!$b) { return 0; } else { if(mysql_affected_rows($this->conn)) { return 1; } else { return 2; } } }}?>
3.編寫添加前台頁面(add.php)
請添加英漢
4.便面dml語句代碼。
dml($sql); if($res==0) { echo "老兄沒有你沒有寫東西吧!"; } else if($res==1) { echo "恭喜添加成功!"; echo "返回"; } else if($res==2) { echo "你添加有誤!"; }}else{ echo"請輸入"; echo"返回"; }?>
以上就是php代碼啦。
mysql操作也是至關重要的哦!
建立資料庫
create database php_dic;
2.建立一張表
create table dic(
dic_id int primary key auto_increment,
enword varchar(20) not null default'',
chword varchar(200) not ull default''
)set character utf8;
3.設定字元集
set names utf8;
4.設定資料庫表編碼和表編碼
alter database php_dic character set utf8;
alter table dic character set utf8;
然後就可以查詢和添加啦~~