Ok so i resolved the issue by myself. Here is a function i used to find statements and run them one by one.
php
/**
* Runs SQL statement with multiple commands.
* @param String $sql The sql code.
*/
public function RunMultipleQueries($sql)
{
// split all the query's into an array
$lines = explode("\n", $sql);
$line_num = 0;
while($line_num < sizeof($lines))
{
// remove white spaces
$lines[$line_num] = trim($lines[$line_num]);
// if line is not sql comment
if(strcmp(substr($lines[$line_num], 0, 2), '--') != 0 && $lines[$line_num] != "")
{
$query .= " " . $lines[$line_num];
// check if this is the end of the query, by checking the last character which should be
// a semi-colon after the trim
if(strcmp(substr($query, strlen($query) - 1, 1), ';') == 0)
{
// remove semi-colon
$query = substr($query, 0, strlen($query) - 1);
$this->RunQuery($query);
$query = "";
}
}
// next line, either
$line_num++;
}
}
It finds the end of the sql statement, which has to be terminated by a semi-colon(can stretch over multiple lines). The only down side to this function is if you try using this code:
sql
INSERT INTO table (text) VALUES("This text is ended by a semi-colon and then a new-line character;
making the function break it wrong");
I can of course check the begining of the lines to find if there a begining of a sql statement, using a simple regex. I'll do it later for now it works for me, and will probably post it here as a snippet since i was not really able to find a simple function that does that on the google. Oh yeah and speed test it of course.
Any thoughts guys?
P.S
This has been more like a blog then anything else, lol.. Just drives me crazy when i can't solve a problem, i have to sit down and solve it before anything else.
This post has been edited by Mike007: 1 Mar, 2008 - 12:16 AM