Posted by
ใช้ Pagination ใน Codeigniter กับ ฐานข้อมูล Microsoft SQL (MSSQL)
คือผมได้มีโอกาศลองใช้ Codeigniter กับ การเขียน โปรแกรมเรียกดูข้อมูลง่ายๆ จาก MSSQL แต่ติดปัญหาเรื่องการแบ่งหน้าด้วย Pagination ลองค้นๆ ดูใน Forum เค้าให้ไปแก้ไฟล์
\system\database\drivers\mssql\mssql_driver.php
ตรงบรรทัด function _limit($sql, $limit, $offset) ให้เป็นแบบนี้
function _limit($sql, $limit, $offset)
{
// Horrible solucion =)
//$i = $limit + $offset;
//return preg_replace(‘/(^\SELECT (DISTINCT)?)/i’,'\\1 TOP ‘.$i.’ ‘, $sql);
$cursorName = ‘mi_cursor_’.md5(strtolower($sql));
$sql = “DECLARE “.$cursorName.” CURSOR DYNAMIC READ_ONLY FOR
“.$sql.”
OPEN “.$cursorName.”
DECLARE @CURSOR AS INT
SELECT @CURSOR = CURSOR_HANDLE FROM MASTER.DBO.SYSCURSORS
WHERE CURSOR_NAME = ‘”.$cursorName.”‘
EXEC SP_CURSORFETCH @CURSOR, 32, “.($offset+1).”, “.$limit.”
EXEC SP_CURSORCLOSE @CURSOR”;
return $sql;
}
ก็จะหายครับ
Sorry, the comment form is closed at this time.
No comments yet.