PHP面试题及答案(六)

1、使用php写一段简单查询,查出所有姓名为“张三”的内容并打印出来
表名User
Name Tel Content Date
张三 13333663366 大专毕业 2006-10-11
张三 13612312331 本科毕业 2006-10-15
张四 021-55665566 中专毕业 2006-10-15
请根据上面的题目完成代码:

$mysql_db = mysql_connect ( " local " , " root " , " pass " );
@
mysql_select_db ( " DB " , $mysql_db );

 


代码
drop   table   if   exists   user ;

/* ============================================================== */
/*  Table: user                                                   */
/* ============================================================== */
create   table   user
(
    `Name`                           
varchar ( 20 ),
    Tel                            
varchar ( 16 ),
    Content                        
varchar ( 255 ),
    `Date`                           date
)
insert   into   user (name,tel,content,`date`)  values ( ' 张三 ' , ' 13333663366 ' , ' 大专毕业 ' , ' 2006-10-11 ' );
insert   into   user (name,tel,content,`date`)  values ( ' 张三 ' , ' 13612312331 ' , ' 本科毕业 ' , ' 2006-10-15 ' );
insert   into   user (name,tel,content,`date`)  values ( ' 张四 ' , ' 021-55665566 ' , ' 中专毕业 ' , ' 2006-10-1 ' );

select   *   from   user   where  name = ' 张三 ' ;

 



代码
<? php
header ( " content-type:text/html; charset=gbk " ); 

$mysql_db = mysql_connect ( " localhost " , " root " , "" );
@
mysql_select_db ( " phpinterview " , $mysql_db );
echo   " <table> " ;
mysql_query ( " set names gbk " );
$result = mysql_query ( " select Name,Tel,Content,Date from user where Name='张三' " ) or  die ( " 错误: " . mysql_error ());
while ( $row = mysql_fetch_array ( $result , MYSQL_BOTH))
{
     
echo   " <tr><td> " . $row [ " Name " ] . " </td><td> " . $row [ " Tel " ] . " </td><td> " .
     
$row [ " Content " ] . " </td><td> " . $row [ " Date " ] . " </td></tr> " ;
}
mysql_free_result ( $result );
echo   " </table> "
?>

 


3、如何使用下面的类,并解释下面什么意思?
class test{
    function Get_test($num){
    $num=md5(md5($num)."En");
    return $num;
    }
}

<? php
/* *
* 使用md5加密数据...
*
*/
class  test{
     
function  Get_test( $num ){
         
$num = md5 ( md5 ( $num ) . " En " );
         
return   $num ;
     }
}
$a = new  test();
echo   $a -> Get_test( " 123 " );
?>

 

4、用javascipt打印 “上海爱吉”

< html >
< head >< title > JS打印 </ title ></ head >
< body >
< script  type ="text/javascript" >
     document.write(
" 上海吉它 " );
</ script >
</ body >
</ html >

 

5、写出 SQL语句的格式 : 插入 ,更新 ,删除
代码
select  expression
from  tablename
where  condition
group   by  columns  asc  
with  rollup
order   by   column   asc
limit offset,
rowcount ;

insert   into  tablename(columname)  values ( exp );
update  tablename  set  columnname = exp   where  condition  order   by   column  limit  rowcount ;
delete   from  tablename  where  condition  order   by   column  limit  rowcount ;

 

你可能感兴趣的:(PHP)