PHP面試題及答案(六)

來源:互聯網
上載者:User
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;

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.