本文主要介绍了php实现sql语句格式化功能的方法,基于github上开源代码实现的sql语句格式化功能,非常简单实用,需要的朋友可以参考下,希望能帮助到大家。
一、问题:
要求使用php实现针对sql语句的格式化功能
二、解决方法:
这里使用github上的开源代码实现sql格式化功能。
github下载地址:https://github.com/till/sql-formatter
或者点击此处本站下载。
使用方法:
include包含sqlformatter.php文件,针对sql语句使用format方法即可实现格式化功能。
具体代码如下:
<?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);
?>
运行结果如下图所示:
相关推荐:
实例分享jquery实现简单日期格式化功能
js的日期格式化功能
扩展js date对象时间格式化功能的小例子_javascript技巧
以上就是sql语句实现格式化功能php代码的详细内容。