返回 全球(切换) 

php面试题三

2012/7/2 13:41:4993
详细描述

44、PHP可以和sql server/oracle等数据库连接吗?(1分)
答:当然可以

45、请写出PHP5权限控制修饰符(3分)
答:public(公共),private(私用),protected(继承)

46、请写出php5的构造函数和析构函数(2分)
答:__construct , __destruct

47、完成以下:
   (一)创建新闻发布系统,表名为message有如下字段 (3分)
  id 文章id
  title 文章标题
  content 文章内容
  category_id 文章分类id
    hits 点击量
答:CREATE TABLE 'message'(
   'id' int(10) NOT NULL auto_increment,
   'title' varchar(200) default NULL,
   'content' text,
   'category_id' int(10) NOT NULL,
   'hits' int(20),
   PRIMARY KEY('id');
   )ENGINE=InnoDB DEFAULT CHARSET=utf8;

    (二)同样上述新闻发布系统:表comment记录用户回复内容,字段如下 (4分)
  comment_id 回复id
  id 文章id,关联message表中的id
  comment_content 回复内容
  现通过查询数据库需要得到以下格式的文章标题列表,并按照回复数量排序,回复最高的排在最前面
  文章id 文章标题 点击量 回复数量
  用一个SQL语句完成上述查询,如果文章没有回复则回复数量显示为0
答:SELECT message.id id,message.title title,IF(message.`hits` IS NULL,0,message.`hits`) hits,
   IF(comment.`id` is NULL,0,count(*)) number FROM message LEFT JOIN
   comment ON message.id=comment.id GROUP BY message.`id`;

  (三)上述内容管理系统,表category保存分类信息,字段如下 (3分)
  category_id int(4) not null auto_increment;
  categroy_name varchar(40) not null;
  用户输入文章时,通过选择下拉菜单选定文章分类
  写出如何实现这个下拉菜单
答:function categoryList()
{
    $result=mysql_query("select category_id,categroy_name from category")
            or die("Invalid query: " . mysql_error());
    print("<select name='category' value=''>/n");
    while($rowArray=mysql_fetch_array($result))
    {
       print("<option value='".$rowArray['category_id']."'>".$rowArray['categroy_name']."</option>/n");
    }
    print("</select>");
}

以上内容来自http://www.buy8866.com


联系我时,请说是在环球搜宝网看到的。
首页我的发布电话