您的位置 首页 php

华育国际 春季 PHP面试题终章

1、 创建新闻发布系统,库名为cms,表名为article,有如下字段,写出创建表的命令?

Id 文章id

Title 文章标题

Content 文章内容

Category_id 文章分类id

Dateline 时间

set names gbk;

create database cms character set utf8;

use cms;

create table article (

id int primary key auto_increment,#文章id

title varchar (30),#文章标题

content varchar (20),#文章内容

category_id int ,#文章分类ID

datetime date #时间

);

2、 写一个操作mysql的类,类名为mysqlDB,类中有连接数据库方法connect()和返回数据库查询结果的二维数组的方法getAll();

mysqlDB.class.php

<?php

//数据库封装类

class mysqlDB

{

public $conn = NULL ;//连接对象

public $rs = NULL ;//结果集对象

//连接数据库

private function __construct()

{

$this->conn = mysql_connect(“localhost”,”name”,”password”);

mysql_query(“set names utf8”);

my sql _select_db(“database”);

}

//防止克隆对象

private function __clone()

{}

//获得该类的对象(单例模式的)

public static function getInstance()

{

static $obj = NULL ;

if ($obj == NULL )

{

$obj = new mysqlDB();

}

return $obj;

}

//执行select语句,返回:二维数组

public function getAll($sql)

{

$result = array ();//存储所有记录

$this->rs = mysql_query($sql);

while ($row = mysql_fetch_array($this->rs))

{

$result[] = $row;

}

return $result;

}

//执行select语句,返回:一维关联数组

public function getRow($sql)

{

$result = NULL ;//存储一条记录

$this->rs = mysql_query($sql);

if ($row = mysql_fetch_array($this->rs))

{

$result = $row;

}

return $result;

}

//执行insert、update、delete语句,返回:受影响的行数

public function exec($sql)

{

mysql_query($sql);

$result = mysql_affected_rows($this->conn);

return $result;

}

//释放结果集

public function freeResult()

{

mysql_free_result($this->rs);

}

//关闭数据库

public function close()

{

mysql_close($this->conn);

}

}

?>

3、 用第一题中的表和第二题中的类写出如下操作:显示点击量最多的10条新闻的标题和发布时间。

insert into article values (‘ ‘,’标题1′,’内容1′,’文章分类ID1’,now());

insert into article values (‘ ‘,’标题2′,’内容2′,’文章分类ID2’,now());

insert into article values (‘ ‘,’标题3′,’内容3′,’文章分类ID3’,now());

insert into article values (‘ ‘,’标题4′,’内容4′,’文章分类ID4’,now());

insert into article values (‘ ‘,’标题5′,’内容5′,’文章分类ID5’,now());

insert into article values (‘ ‘,’标题6′,’内容6′,’文章分类ID6’,now());

insert into article values (‘ ‘,’标题7′,’内容7′,’文章分类ID7’,now());

insert into article values (‘ ‘,’标题8′,’内容8′,’文章分类ID8’,now());

insert into article values (‘ ‘,’标题9′,’内容9′,’文章分类ID9’,now());

insert into article values (‘ ‘,’标题10′,’内容10′,’文章分类ID10’,now());

insert into article values (‘ ‘,’标题11′,’内容11′,’文章分类ID11’,now());

insert into article values (‘ ‘,’标题12′,’内容12′,’文章分类ID12’,now());

insert into article values (‘ ‘,’标题13′,’内容13′,’文章分类ID13’,now());

select * from article;

<?php

header(“content-type:text/ html ;charset=utf-8″);

include_once ‘mysqlDB.class.php’;

$sql = “select title,datetime from article limit 10”;

$conn = mysqlDB::getInstance();

$result = $conn->getAll($sql);

?>

<!DOCTYPE html PUBLIC “-//W3C//D td HTML 4.01 Transitional//EN” “”>

<html>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>

<title>Insert title here</title>

</head>

<body>

<table border=’1′ align=”center”>

<tr>

<td>标题</td>

<td>时间</td>

</tr>

<?php

foreach ($result as $v){

?>

<tr>

<td><?php echo $v[‘title’]?></td>

<td><?php echo $v[‘datetime’]?></td>

</tr>

<?php

}

?>

</table>

</body>

</html>

4、 如果要把article表分成多个表,写出你的大体思路。

create table table2 select * from table1 order by id limit 1,100

create table table3 select * from table1 order by id limit 100,100

create table table4 select * from table1 order by id limit 200,100

5、 请写一个函数验证电子邮件的格式是否正确。

[\w!#$%&’*+/=?^_`{|}~-]+(?:\.[\w!#$%&’*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?

文章来源:智云一二三科技

文章标题:华育国际 春季 PHP面试题终章

文章地址:https://www.zhihuclub.com/78856.shtml

关于作者: 智云科技

热门文章

评论已关闭

38条评论

  1. Important All drugs that contain PDE-5 inhibitors act on the cardiovascular system, dilating blood vessels

  2. Significant improvement in ejaculatory control with dapoxetine 30 mg or 60 mg, as compared with placebo, was found in all RCTs in Table 3

  3. Although this claim is far from being supported by clinical trials, SARMs are promoted as a safer, albeit more expensive, alternative to steroidal androgens.

  4. Other PCOS diet books seem to be a mixture of different ideas, all thrown together, with complicated lists of what you can eat and cannot eat.

  5. 8 However, it can be seen in adults due to autoinoculation and rarely, person- to- person nonsexual contact or fomites in outbreak settings.

  6. Beijing, China Si bien muchos de hechos contienen activos que a lo mejor sГіlo podrГ­as conseguir si tuvieras acceso a un laboratorio, o tuvieras conocimientos de quГ­mica

  7. Greater satisfaction with the learning environment in early years of training has been found to provide stimulus to learning in future years

  8. Authors Ishii J, Kitazawa R, Mori K, McHugh KP, Morii E, Kondo T, Kitazawa S Journal J Cell Biochem Page No 896 Wed Oct 15 00 00 00 EDT 2008 Volume Year 105 2008 Product Usage

  9. cyproheptadine citalopram actavis alcohol And this film, actually, we trace back even more to see what is the time before Hong Kong, where they came from, what is their life

  10. t able to attend the hearing on Friday because at this point in treatment, she should not be moved

  11. A Randomized Phase IIb Study of Low dose Tamoxifen in Chest irradiated Cancer Survivors at Risk for Breast Cancer

  12. Cost is 85 as of April 2015, with a discount for shelters In contrast, the recommended antibiotic treatment protocols for actinomycosis of the jawbone start with intravenous broad spectrum antibiotics amoxicillin clavulanic acid, ampicillin sulbactam for 3 4 weeks and continue with oral penicillin for 9 12 months or longer 45, 47, 48, whereas Actinomyces strains are sensitive to beta lactam compounds, but these compounds show very poor potential to penetrate fibrotic, necrotic and inflamed tissues and large bacterial aggregates 49

  13. Bipolar disorder BD has a complex and variable clinical picture which is characterized by many different phacets and phases and as a result its therapeutical options are also complex and often unsatisfactory Apples Apricots Cantaloupe Raspberries Oranges in moderation this fruit s high in sugar Pears Prunes

  14. Type 2 diabetes was the twelfth main contributor to whole burden Overall, the burden from sort 2 diabetes elevated slightly from 18 in 2003 to 22 in 2015 Type 1 diabetes contributed to zero3 of Australia s disease burden in 2015 unchanged from each 2003 and 2011 As sort 2 diabetes is a progressive situation, drugs may finally be required, often in the type of tablets However, when you have can metformin make your blood sugar drop diabetes, your body is unable to break down glucose into energy

  15. Do not operate machinery or drive a car until you know how this medication affects your abilities

  16. If you like dairy products, know that they may cause cramping in some people during treatment

  17. Based on these limited data, one can cautiously conclude that exposure to chemotherapy for the treatment of maternal breast cancer in utero does not appear to affect the normal development of children so exposed

  18. Patients should be counseled that antibacterial drugs, including doxycycline should only be used to treat bacterial infections

  19. He s not a fool, Ye Fan defeated Ling Tian and others before 6 Nuclear Magnetic Resonance NMR Spectroscopy

  20. The device will be priced below the current 3DS in an attempt to introduce more customers to the companyГў

  21. Samiy AH, Brown JL, Globus DL, Kessler RH, Thompson DD Interrelation between renal transport systems of magnesium and calcium

网站地图