The method for formatting SQL statements in PHP is original, sqlfont

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.