Skip to content

Commit b662def

Browse files
committed
fix: remove backticks, single and double quotation marks from query
Credits to: King Goddard
1 parent 0df30c7 commit b662def

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/LightSQLParser.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
/**
66
* Light SQL Parser Class
77
* @author Marco Cesarato <cesarato.developer@gmail.com>
8-
* @copyright Copyright (c) 2018
8+
* @copyright Copyright (c) 2020
99
* @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
1010
* @link https://github.com/marcocesarato/PHP-Light-SQL-Parser-Class
11-
* @version 0.1.97
11+
* @version 0.1.98
1212
*/
1313
class LightSQLParser
1414
{
@@ -23,9 +23,9 @@ class LightSQLParser
2323
*/
2424
public function __construct($query = '') {
2525
$this->query = $query;
26-
if (empty(self::$connectors_imploded))
27-
self::$connectors_imploded = implode('|', self::$connectors);
28-
return $this;
26+
if (empty(self::$connectors_imploded)) {
27+
self::$connectors_imploded = implode('|', self::$connectors);
28+
}
2929
}
3030

3131
/**
@@ -38,12 +38,12 @@ public function setQuery($query) {
3838

3939
/**
4040
* Get SQL Query method
41-
* @param $query
41+
* @param $methodQuery
4242
* @return string
4343
*/
44-
public function method($query = null) {
44+
public function method($methodQuery = null) {
4545
$methods = array('SELECT', 'INSERT', 'UPDATE', 'DELETE', 'RENAME', 'SHOW', 'SET', 'DROP', 'CREATE INDEX', 'CREATE TABLE', 'EXPLAIN', 'DESCRIBE', 'TRUNCATE', 'ALTER');
46-
$queries = empty($query) ? $this->_queries() : array($query);
46+
$queries = empty($methodQuery) ? $this->_queries() : array($methodQuery);
4747
foreach ($queries as $query) {
4848
foreach ($methods as $method) {
4949
$_method = str_replace(' ', '[\s]+', $method);
@@ -175,6 +175,9 @@ protected function _queries() {
175175
$queries = preg_replace('#;(?:(?<=["\'];)|(?=["\']))#', '', $queries);
176176
$queries = preg_replace('#[\s]*UNION([\s]+ALL)?[\s]*#', ';', $queries);
177177
$queries = explode(';', $queries);
178+
foreach ($queries as &$query) {
179+
$query = str_replace(array('`', '"', "'"), '', $query);
180+
}
178181
return $queries;
179182
}
180183
}

0 commit comments

Comments
 (0)