当前位置:Gxlcms > PHP教程 > 小词典(php)

小词典(php)

时间:2021-07-01 10:21:17 帮助过:12人阅读

  • 查询前台页面(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;

    然后就可以查询和添加啦~~

    人气教程排行