Example of oracle paging function implemented in PHP_php skills
The example in this article describes the oracle paging function implemented in PHP. Share it with everyone for your reference, the details are as follows:
MySQL has a limit. When paging, we can use limit 30, 40, but Oracle does not have a limit. Use other methods instead - rownum.
1. Underlying methods
/** * 数据连接 */ function connect($db_user, $db_pwd, $db_name, $db_nls) { $this->dbh = oci_connect($db_user, $db_pwd, $db_name, $db_nls); } function getall($query, $start=0, $rows=-1) { $this->dbh = emptyempty($this->dbh) ? $this->connect() : $this->dbh; $this->sth = oci_parse($this->dbh, $query); oci_execute($this->sth, OCI_DEFAULT) or $this->error($this->sth, $query); oci_fetch_all($this->sth, $res, $start, $rows, OCI_FETCHSTATEMENT_BY_ROW+OCI_ASSOC); return $res; } /** * 获取分页数 * * $query string 查询语句 * $total int 总条数 * $page int 页数 * $rows int 每页显示数 * @return integer 总行数 */ function getpage($query, $total, $page, $rows=VAR_PAGENAV_ROWS) { $start_row = ($page - 1) * $rows + 1; $start_row = $start_row > $total ? 1 : $start_row; $end_row = $start_row + $rows - 1; $end_row = $end_row > $total ? $total : $end_row; $query = "SELECT * FROM ( SELECT ROWNUM as row_num, r.* FROM ( $query ) r WHERE ROWNUM <= $end_row ) WHERE $start_row <= row_num"; return $this->getall($query); } /** * 获取一个查询的总行数 * * $string $sql 查询语句 * * return integer 总行数 */ function getcount($sql){ $subSQL = 'select count(*) '.stristr($sql, 'from'); return $this->getone($subSQL); } function getone($query) { $row = $this->getrow($query); if (is_array($row)) $one = current($row); else $one = ''; unset($row); return $one; } function getrow($query) { if (false === stripos($query, 'COUNT(')) { if (false === stripos($query, 'WHERE')) { $query .= ' WHERE ROWNUM = 1'; } else { $query .= ' AND ROWNUM = 1'; } } $result = $this->getall($query, 0, 1); if (emptyempty($result)) $row = array(); else $row = $result[0]; unset($result); return $row; }
I will write some comments on the two main methods
2. Calling method
$total = $this->db->getcount($sql); $result = $this->db->getpage($sql,$total,$page,$page_number);
Only part of the code is posted above, which is also the core.
Readers who are interested in more content related to PHP database operations can check out the special topics of this site: "Summary of common PHP database operation skills", "Summary of PHP database operation skills based on pdo ” and “Introduction Tutorial on PHP MySQL Database Operation”.
I hope this article will be helpful to everyone in PHP programming.

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools
