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 who need it can refer to it. I hope it can help everyone.
1. Problem:
Requires the use of php to implement the formatting function for sql statements
2. Solution:
Here we use the open source on github The code implements SQL formatting function.
github download address: https://github.com/till/sql-formatter
Or click here to download from this site.
Usage:
include contains the SqlFormatter.php file, and the formatting function can be achieved by using the format method for the sql statement.
The specific code is as follows:
<?php include('SqlFormatter.php'); $sql="SELECT DATE_FORMAT(b.t_create, '%Y-%c-%d') 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,'a', 29,30,31,321,33,34,3542,361,327,38,39,40,41,42,431,4422,415,4546,47,48,'a') AND d.title IS NOT NULL AND t_create >= DATE_FORMAT((DATE_SUB(NOW(),INTERVAL 1 DAY)),'%Y-%c-%d') AND t_create < DATE_FORMAT(NOW(), '%Y-%c-%d') ORDER BY d.id LIMIT 2,10) a, orc_scheme_detail b WHERE a.id = b.id"; echo SqlFormatter::format($sql); ?>
The running results are as shown below:
##Related recommendations:Example sharing jQuery to implement simple date formatting function
Extended JS Date object time formatting Small example of function_javascript skills
The above is the detailed content of SQL statement to implement formatting function php code. For more information, please follow other related articles on the PHP Chinese website!