现在的位置: 首页 > 综合 > 正文

绿盟2013web实习生面试题

2012年12月07日 ⁄ 综合 ⁄ 共 2078字 ⁄ 字号 评论关闭

1、             limitn,m

limit 起始位置(0开始算),显示条数;

上例:SELECT * FROM `test` limit n,m 他的起始位置写的是n,由于是从0开始算起的,而数据库中的id是从1开始的,所以自然真正的起始位置是n+1,后面的m代表显示m条记录。

2、             php连接数据库代码

      //mysql_connect(servername,username,password);

servername

可选。规定要连接的服务器。默认是 "localhost:3306"。

username

可选。规定登录所使用的用户名。默认值是拥有服务器进程的用户的名称。

password

可选。规定登录所用的密码。默认是 ""。

      $con=mysql_connect("127.0.0.1","root","root");

      if($con){

             echo"连接成功";

      }else{

             echo"连接失败";

               }

3、             mysql备份与还原

mysqldump:数据库备份

mysqldump -uroot -proot  shop>d:\backup.sql

上面命令是把shop数据库备份到d盘。

mysqldump是mysql用于转存储数据库的实用程序。它主要产生一个SQL脚本,其中包含从头重新创建数据库所必需的命令CREATE TABLE INSERT等。

mysqldump这个需要在环境变量加入mysql安装目录下的bin,如果没有加入环境变量中,需要切换到mysql安装目录下的bin目录下。

数据库还原:

mysql  –uroot –proot  shop< d:\backup.sql

把backup.sql还原到shop数据库中。

4、             sql注入语句

场景1:select * from user where name=’$name’  and pwd=’$passwd’,规范的语句,带分号。

1、万能密码:bb’ or 1=’1

select * from user where name=’admin’  and pwd=’bb’ or 1=’1’

2、万能用户名: bb’ union select * from user;/*

select * from user where name=’bb’ union select * from user;/*  and pwd=’admin’

场景2:select * from user where name=$name and pwd=$passwd,不规范的语句,不带分号。

1、万能密码:数字 union select * from user

select * from user where name=88  and pwd=88 union select * from user

2、万能用户名:数字  union select *from cuser;/*

select * from user where name=88  union select * from cuser;/* and pwd=88

如何防范:

在服务器中magic_quotes_gpc(php.ini)设置成on,场景1 的万能密码和用户名失效。服务器会转义。name=’abc’=>name=\’abc\’,高手会用char(96)代表单引号。场景依然可以用。

密码匹配法:先根据用户名去检索密码,然后在和表单提交的密码去匹配,如果一样,匹配成功。否则失败。

pdo::prepare()预处理,防止sql注入漏洞。默认下pdo是没有开启的。

php::addslashes():使用反斜线引用字符串。

5、             mysql 视图

使用视图的理由:

1、         安全性:可以通过grant控制权限

2、         查询性能提高

3、         灵活性

4、         复杂的查询需求

创建视图:

CREATE VIEW teams(id,age,sex) AS SELECT id,age,sexform  user

with check option:对视图进行更新操作的时,需要检查更新后的值是否还是满足视图公式定义的条件。通俗点,就是所更

新的结果是否还会在视图中存在。如果更新后的值不在视图范围内,就不允许更新。如果创建视图的时候,没有加上with check option,更新视图中的某项数据的话,mysql并不会进行有效性检查。

5、         项目遇到最大问题

g.goods_id in (select  goods_id from `mineshop`.`sc_goods_attr` where (attr_id=4 and  attr_value like '2012%') or(attr_id=3and  attr_value like '白%') or(attr_id=39 and  (attr_value>=3.0 and attr_value<=3.9))   group by goods_id havingcount(goods_id)=3)

抱歉!评论已关闭.