Home > Backend Development > PHP Tutorial > php 查询sql server 2008的有关问题

php 查询sql server 2008的有关问题

WBOY
Release: 2016-06-13 12:06:52
Original
862 people have browsed it

php 查询sql server 2008的问题
我想要php分页从sql server 2008获取数据,

1.   mysql 可以 limit n,m  ,sql server没有
2.   要分页获取 union  后的数据, 网上看到有用rownum 和 top 的,请问怎么与union结合实现呢


我的结果集类似于

(select A,B,C,D from t1) union (select '100' as A ,B,C,D  from t2)  union (select A,B,C,D from t3)
Copy after login


想限制每次返回结果集的 哪一条到哪一条


------解决思路----------------------
这样写:
$sql = '你的sql查询指令';<br />$start = 1; //起始偏移<br />$pagesize = 20; //每页行数<br />$sqls =<<< SQL<br />SELECT * FROM <br />(<br />SELECT A.*, ROWNUM RN <br />FROM ($sql) A <br />WHERE ROWNUM < $start+$pagesize<br />)<br />WHERE RN >= $start<br />SQL;
Copy after login
$sqls 就是最终执行的查询语句

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template