A detailed analysis of how PHP implements SQL statement formatting methods

黄舟
Release: 2023-03-14 15:06:02
Original
1331 people have browsed it

This article mainly introduces the method of implementing SQL statement formatting function in PHP. The SQL statement formatting function is implemented based on the open source code on github. It is very simple and practical. Friends in need can refer to the example of this article

Describes how PHP implements the SQL statement formatting function. Share it with everyone for your reference, the details are as follows:

1. Question:

Requires the use of php to implement the formatting function for sql statements

2. Solution:

Here we use the open source code on github to implement the SQL formatting function.

Or click hereDownload from this site.

Usage:

include contains the SqlFormatter.php file. Use the format method for the sql statement to achieve the formatting function.

The specific code is as follows:


<?php
include(&#39;SqlFormatter.php&#39;);
$sql="SELECT DATE_FORMAT(b.t_create, &#39;%Y-%c-%d&#39;) dateID, b.title memo
  FROM (SELECT id FROM orc_scheme_detail d WHERE d.business=208
  AND d.type IN (29,30,31,321,33,34,3542,361,327,38,39,40,41,42,431,4422,415,4546,47,48,&#39;a&#39;,
  29,30,31,321,33,34,3542,361,327,38,39,40,41,42,431,4422,415,4546,47,48,&#39;a&#39;)
  AND d.title IS NOT NULL AND t_create >=
  DATE_FORMAT((DATE_SUB(NOW(),INTERVAL 1 DAY)),&#39;%Y-%c-%d&#39;) AND t_create
  < DATE_FORMAT(NOW(), &#39;%Y-%c-%d&#39;) ORDER BY d.id LIMIT 2,10) a,
  orc_scheme_detail b WHERE a.id = b.id";
echo SqlFormatter::format($sql);
?>
Copy after login

The running results are as shown below:

The above is the detailed content of A detailed analysis of how PHP implements SQL statement formatting methods. For more information, please follow other related articles on the PHP Chinese website!

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