The method for formatting SQL statements in PHP is original, sqlfont
This article describes how to format SQL statements in PHP. We will share this with you for your reference. The details are as follows:
I. Problems:
You must use php to format SQL statements.
Ii. solution:
Here we use the open source code on github to implement the SQL Formatting Function.
Github: https://github.com/till/sql-formatter
Or click hereDownload from this site.
Usage:
Include contains the SqlFormatter. php file. You can use the format method to format SQL statements.
The Code is as follows:
<?phpinclude('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);?>
Shows the running result:
PS:For more usage, see examples. php examples in the source code.