motormichael12
07-03-2008, 04:43 AM
I am making a script where a user can execute mysql queries, but I need it to split the queries by the semicolon and also find the type of query it is. I have this code at the moment:
if ($query)
{
$these = explode(";", $query);
for($i=0;$i<count($these);$i++)
{
$splitagain = explode(" ", trim($these[$i]));
for($x=0;$x<count($these);$x++)
{
echo "i: " . $i . "<br>";
echo "x: " . $x . "<br>";
$query_type = strtoupper($splitagain[x]);
echo "splitagain[x]: " . $splitagain[$x] . "<br>";
echo "these[x]: " . $these[$x] . "<br><br>";
switch ($query_type){
case 'SHOW':
case 'SELECT':
$this->query_display($query);
break;
case 'UPDATE':
$this->query_background($query);
break;
}
}
}
}
Now lets say I enter in the following query:
select * from config; update table set er = 9 where er = 3
The output:
i: 0
x: 0
splitagain[x]: select
these[x]: select * from config
i: 0
x: 1
splitagain[x]: *
these[x]: update table set er = 9 where er = 3
i: 1
x: 0
splitagain[x]: update
these[x]: select * from config
i: 1
x: 1
splitagain[x]: table
these[x]: update table set er = 9 where er = 3
I only need it to produce one output, so that for this query it would be like:
splitagain[x]: select
these[x]: select * from config
splitagain[x]: update
these[x]: update table set er = 9 where er = 3
Can anyone help me with this?
if ($query)
{
$these = explode(";", $query);
for($i=0;$i<count($these);$i++)
{
$splitagain = explode(" ", trim($these[$i]));
for($x=0;$x<count($these);$x++)
{
echo "i: " . $i . "<br>";
echo "x: " . $x . "<br>";
$query_type = strtoupper($splitagain[x]);
echo "splitagain[x]: " . $splitagain[$x] . "<br>";
echo "these[x]: " . $these[$x] . "<br><br>";
switch ($query_type){
case 'SHOW':
case 'SELECT':
$this->query_display($query);
break;
case 'UPDATE':
$this->query_background($query);
break;
}
}
}
}
Now lets say I enter in the following query:
select * from config; update table set er = 9 where er = 3
The output:
i: 0
x: 0
splitagain[x]: select
these[x]: select * from config
i: 0
x: 1
splitagain[x]: *
these[x]: update table set er = 9 where er = 3
i: 1
x: 0
splitagain[x]: update
these[x]: select * from config
i: 1
x: 1
splitagain[x]: table
these[x]: update table set er = 9 where er = 3
I only need it to produce one output, so that for this query it would be like:
splitagain[x]: select
these[x]: select * from config
splitagain[x]: update
these[x]: update table set er = 9 where er = 3
Can anyone help me with this?