php面试题4

1、COOKIE、SESSION的联系和区别,多台web服务器如何共享SESSION?
   2、HTTP协议中的POST和GET有何区别?
   3、一段php代码,写出输出结果,不难,但设了小小的陷阱。
   4、reqiure的include都可包含文件,二者的区别何在?
    (至此处我做的还不错,往下就惨了)
   5、php中WEB上传文件的原理是什么,如何限制上传文件的大小?
   6、写一个函数,可以遍历文件夹下的所有文件和文件夹。
   7、8、中间有几个unix shell的题目(好像是两个),因为不懂,不记得这些题目了
   9、有mail.log的一个文档,内容为若干邮件地址,其中用'\n'将邮件地址分隔。要求从中挑选出xxx.com的邮件地址(包括从文件读取、过滤到列印出来)。

1)Which statement shows the maximum salary paid in each job category of each department?_______
A. select dept_id, job_cat,max(salary) from employees where salary > max(salary);
B. select dept_id, job_cat,max(salary) from employees group by dept_id,job_cat;
C. select dept_id, job_cat,max(salary) from employees;
D. select dept_id, job_cat,max(salary) from employees group by dept_id;
E. select dept_id, job_cat,max(salary) from employees group by dept_id,job_cat,salary;

2)description of the students table:
sid_id number
start_date date
end_date date
which two function are valid on the start_date column?_________。
A.sum(start_date)
B.avg(start_date)
C.count(start_date)
D.avg(start_date,end_date)
E.min(start_date)
F.maximum(start_date)
3)for which two constraints does the oracle server implicitly create a unique index?______。
A. not null
B. primary
C. foreign key
D. check
E. unique
4)in a select statement that includes a where clause,where is the group by clause placed in the select statement?______。
A. immediately after the select clause
B. before the where clause
C. before the from clause
D. after the order by clause
E. after the where clause
5)in a select statement that includes a where clause,where is the order by clause placed in the select statement?______.
A.immediately after the select clause
B.before the where clause
C.after all clause
D.after the where clause
E.before the from clause
6)evaluate there two sql statements______.
Select last_name,salary from employees order by salary;
Select last_name,salary from employees order by 2 asc;
A.the same result B.different result C.the second statement returns a syntax error
7) you would like to display the system date in the format“20051110 14:44:17”。Which select statement should you use?______。
A. select to_date(sydate,’yearmmdd hh:mm:ss’)from dual;
B. select to_char(sydate,’yearmonthday hh:mi:ss’)from dual;
C. select to_date(sydate,’yyyymmdd hh24:mi:ss’)from dual;
D. select to_char(sydate,’yyyymmdd hh24:mi:ss’)from dual;
E. select to_char(sydate,’yy-mm-dd hh24:mi:ss’)from dual;
8)which select statement will the result ‘ello world’from the string‘Hello world’?______.
A. select substr(‘Hello World’,1)from dual;
B. select substr(trim(‘Hello World’,1,1))from dual;
C. select lower(substr(‘Hello World’,1))from dual;
D. select lower(trim(‘H’from‘Hello World’))from dual;
9)which are DML statements(choose all that apply)______.
A.commit B.merge C.update D.delete E.creat F.drop
10)Select 语句中用来连接字符串的符号是______.
DA. “+” B. “&” C.“||” D.“|”
问答题: 什么是聚集索引,什么是非聚集索引,什么又是主键?

1. 如何用php的环境变量得到一个网页地址的内容?ip地址又要怎样得到?
[php]
echo $_SERVER ['PHP_SELF'];
echo $_SERVER ['SERVER_ADDR'];
[/php]


2. 求两个日期的差数,例如2007-2-5 ~ 2007-3-6 的日期差数
[php]
$begin=strtotime('2007-2-5');
$end=strtotime('2007-3-6');
echo ($end-$begin)/(24*3600);
[/php]


3. 请写一个函数,实现以下功能:
字符串“open_door” 转换成 “OpenDoor”、”make_by_id” 转换成 ”MakeById”。
[php]
function changeStyle(& $str) {

/*$str = str_replace ( "_", " ", $str );
$str = ucwords ( $str );
$str = str_replace ( " ", "", $str );
return $str;*/

$arrStr=explode('_',$str);
foreach($arrStr as $key=>$value){
$arrStr[$key]=strtoupper(substr($value,0,1)).substr($value,1);
}
return implode('',$arrStr);
}
$s = "open_door";
echo changeStyle ( $s );
[/php]

4. 要求写一段程序,实现以下数组$arr1转换成数组$arr2:
[php]$arr1 = array (
'0' => array ('fid' => 1, 'tid' => 1, 'name' =>'Name1' ),
'1' => array ('fid' => 1, 'tid' => 2 , 'name' =>'Name2' ),
'2' => array ('fid' => 1, 'tid' => 5 , 'name' =>'Name3' ),
'3' => array ('fid' => 1, 'tid' => 7 , 'name' =>'Name4' ),
'4' => array ('fid' => 3, 'tid' => 9, 'name' =>'Name5' )
);
$arr2 = array (
'0' => array (
'0' => array ( 'tid' => 1, 'name' => 'Name1'),
'1' => array ( 'tid' => 2, 'name' => 'Name2'),
'2' => array ( 'tid' => 5, 'name' => 'Name3'),
'3' => array ( 'tid' => 7, 'name' => 'Name4')
),
'1' => array (
'0' => array ( 'tid' => 9, 'name' => 'Name5' )
)
);
<?php
$arr1 = array (
'0' => array ('fid' => 1, 'tid' => 1, 'name' =>'Name1' ),
'1' => array ('fid' => 1, 'tid' => 2 , 'name' =>'Name2' ),
'2' => array ('fid' => 1, 'tid' => 5 , 'name' =>'Name3' ),
'3' => array ('fid' => 1, 'tid' => 7 , 'name' =>'Name4' ),
'4' => array ('fid' => 3, 'tid' => 9, 'name' =>'Name5' )
);
function changeArrayStyle($arr){
foreach($arr as $key=>$value){
$result[$value['fid']][]=$value;
}
return array_values($result);
}
$arr2=changeArrayStyle($arr1);
echo "<pre>";
var_dump($arr2);
[/php]

5. 请简述数据库设计的范式及应用。
一般第3范式就足以,用于表结构的优化,这样做既可以避免应用程序过于复杂同时也避免了SQL语句过于庞大所造成系统效率低下。
ANSWER:
第一范式:若关系模式R的每一个属性是不可再分解的,再属于第一范式。
第二范式:若R属于第一范式,且所有的非码属性都完全函数依赖于码属性,则为第二范式。
第三范式:若R属于第二范式,且所有的非码属性没有一个是传递函数依赖于候选码,则属于第三范式。
6.一个表中的Id有多个记录,把所有这个id的记录查出来,并显示共有多少条记录数,用SQL语句及视图、存储过程分别实现。
存储过程:
[php]
DELIMITER //
create procedure proc_countNum(in columnId int,out rowsNo int)
begin
select count(*) into rowsNo from member where member_id=columnId;   
end
call proc_countNum(1,@no);
select @no;

[/php]
视图:
create view v_countNum as select member_id,count(*) as countNum from member group by member_id
select countNum from v_countNum where member_id=1
7 表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。
[php]select
case
when first_name>middle_name then
case when first_name>last_name then first_name
else last_name end
else
case when middle_name>last_name then middle_name else last_name
end
end as name
from member
[/php]
8请简述项目中优化sql语句执行效率的方法,从哪些方面,sql语句性能如何分析?
ANSWER: sql优化有鸟用,不如直接加索引。
9 如果模板是用smarty模板。怎样用section语句来显示一个名为$data的数组。比如:
[php]$data = array(
[0] => array( [id]=8 [name]=’name1′)
[1] => array( [id]=10 [name]=’name2′)
[2] => array( [id]=15 [name]=’name3′)
……
)[/php]
写出在模板页的代码? 若用foreach语句又要怎样显示呢?
占无答案.
10 写一个函数,能够遍历一个文件夹下的所有文件和子文件夹。(目录操作)
[php] <?php
$d = dir(dirname(__file__));
//echo "Handle: " . $d->handle . "\n";
//echo "Path: " . $d->path . "\n";
while ( false !== ($entry = $d->read ()) ) {
echo $entry . "<br />";
}
$d->close ();
[/php]

11 两张表 city表和province表。分别为城市与省份的关系表。
city:
id City Provinceid
1 广州 1
2 深圳 1
3 惠州 1
4 长沙 2
5 武汉 3
………. 广州
province:
id Province
1 广东
2 湖南
3 湖北
……….
(1) 写一条sql语句关系两个表,实现:显示城市的基本信息。?
(2) 显示字段:城市id ,城市名, 所属省份 。
如:
Id(城市id) Cityname(城市名) Privence(所属省份)
。。。。。。。。。
。。。。。。。。。
(2)如果要统计每个省份有多少个城市,请用group by 查询出来。?
显示字段:省份id ,省份名,包含多少个城市。
ANSWER:
1.select A.id,A.Cityname,B.Province from city A,province B where A.provinceid=B.id
2.select B.id,B.Province,count(*) as num from city A,province B where A.provinceid=B.id group by B.id
12. 按照你的经验请简述软件工程进行软件开发的步骤。以下工具Rational Rose、PowerDesigner、Project、VSS或CVS、TestDirector使用过那种,有缺点是什么?
公司用dbdesigner及cvs,测试管理工具用的是Mantis
13. 请简述操作系统的线程与进程的区别。列举LINUX下面你使用过的软件?
14. 请使用伪语言结合数据结构冒泡排序法对以下一组数据进行排序 10 2 36 14 10 25 23 85 99 45。
[php]function bubble_sort(& $arr){
$number=count($arr);
for($i=0;$i<$number-1;$i++){
for($j=0;$j<$number-1-$i;$j++){
   if($arr[$j]>$arr[$j+1]){
    $tmp=$arr[$j];
    $arr[$j]=$arr[$j+1];
    $arr[$j+1]=$tmp;
   }
}
}
}
$str="10 2 36 14 10 25 23 85 99 45";
$arr=explode(" ",$str);
bubble_sort($arr);
echo "<pre>";
var_dump($arr);
[/php]

6.写出三种以上MySQL数据库存储引擎的名称(提示:不区分大小写)
MyISAM、InnoDB、BDB(Berkeley DB)、Merge、Memory(Heap)、Example、Federated、Archive、CSV、Blackhole、MaxDB 等等十几个引擎

7.说出你所知道的三种以上开源数据库的名称(提示:想想目前国外流行的开源数据库)
MySQL、SQLite、BDB(Berkeley DB)、PostgreSQL、Firebird

8.MySQL数据库中的字段类型varchar和char的主要区别是什么?那种字段的查找效率要高,为什么?
Varchar是变长,节省存储空间,char是固定长度。查找效率要char型快,因为varchar是非定长,必须先查找长度,然后进行数据的提取,比char定长类型多了一个步骤,所以效率低一些

9.说出MySQL 4.0和MySQL 4.1版本的最主要的两个区别。如果你使用过MySQL 5,请说说MySQL 5跟MySQL 4的主要区别。(后半题选作)

MySQL 4.1 主要是比MySQL 4.0多了子查询和字符编码的支持两个特点。
MySQL5增加的功能比MySQL4要更多,包括存储过程、视图、事务等等

10.MySQL数据库基本的三个优化法则是什么,除了增加硬件和带宽?(提示:从服务配置、应用、开发角度考虑)
(1)系统服务优化,把MySQL的key_buffer、cache_buffer、query_cache等增加容量
(2)给所有经常查询的字段增加适当的索引
(3)优化SQL语句,减少Ditinct、Group、Join等等语句的操作

原文地址:https://www.cnblogs.com/bafeiyu/p/2628848.html