if (!function_exists('parse_sql')) {
/**
* 分割sql语句
* @param string $content sql内容
* @param array $prefix 替换前缀
* @param bool $limit 如果为1,则只返回一条sql语句,默认返回所有 *
* @return array|string 除去注释之后的sql语句数组或一条语句
*/
function parse_sql($sql = '', $prefix = [], $limit = 0) {
// 被替换的前缀
$from = '';
// 要替换的前缀
$to = '';
// 替换表前缀
if (!empty($prefix)) {
$to = current($prefix);
$from = current(array_flip($prefix));
}
if ($sql != '') {
// 纯sql内容
$pure_sql = [];
// 多行注释标记
$comment = false;
// 按行分割,兼容多个平台
$sql = str_replace(["\r\n", "\r"], "\n", $sql);
$sql = explode("\n", tr
php sql 语法解析函数,非常实用
最新推荐文章于 2024-04-15 09:56:36 发布