設為首頁收藏本站

 取回密碼
 註冊
搜尋
熱搜: Redump discuz
檢視: 15|回覆: 0

【分享】 PHP 使用 MSSQL Server 如何分頁

[複製連結]
發表於 2024年4月26日 10:32:13 | 顯示全部內容 |閱讀模式
<?php
/* Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
$serverName = "sqlserver";
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>"opencourse");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
     echo "Could not connect.\n";
     die( print_r( sqlsrv_errors(), true));
}
/* Set up and execute the query. */
$tsql = "select dpt_name, area_name, cur_code, cur_name, tea_name from cur_list";
$stmt = sqlsrv_query( $conn, $tsql,array(),
                     array( "Scrollable" => SQLSRV_CURSOR_STATIC ));
                     
if( $stmt === false)
{
     echo "Error in query preparation/execution.\n";
     die( print_r( sqlsrv_errors(), true));
}
/* Retrieve each row as an associative array and display the results.*/
$i=0;
$offset = 4;
for ($i=0;$i<10;$i++) {
$rs = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC, SQLSRV_SCROLL_ABSOLUTE,$offset+$i);
  echo $rs['dpt_name'].' '.$rs['cur_name']."<br>\n";
}
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
作者文章推薦
懶得打字嗎?讓本助手協助你 【使用進階編輯器請點選右方進階模式】
您需要登入後才可以回覆 登入 | 註冊

本版積分規則

手機版|Archiver|漁家小舖

GMT+8, 2024年5月6日 19:20 , Processed in 0.470809 second(s), 17 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回覆 返回頂端 返回清單