这篇文章主要介绍了php实现sql语句格式化功能的方法,基于github上开源代码实现的sql语句格式化功能,非常简单实用,需要的朋友可以参考下
本文实例讲述了php实现sql语句格式化功能的方法。分享给大家供大家参考,具体如下:
一、问题:
要求使用php实现针对sql语句的格式化功能
二、解决方法:
具体代码如下:
<?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);
?>
运行结果如下图所示:
相关推荐:
如何使用vue.js实现价格格式化(代码附上)
vue过滤器格式化方法详解
python格式化输出%s和%d
以上就是php实现sql语句格式化功能的详细内容。