I am working on a project where I need to save some variables to a database and retrieve some of those variables in a class to recalculate the next batch of variables.
However I came to realise that the current project is running too slow and find out where the leak was: in storing those variables. (Insert statement in PHP)
Since the insert statement can get in a pretty big for loop, like this ($auctionobjects and numberofdays is filled in by the user, $hours == 24):
for($i = 0; $i< $numberofdays) {
for ($n = 0; $n < $hours) {
for ($k = 0; $k < $auctionobjects) {
$strSql = 'insert into results (vars) values ()'
$blnOke = $objDatabase->query($strSql)
}
}
}
The waiting time can get pretty long, which is not desirable as the simulation must be able to run for a pretty long time.
Now my idea was to get an insert statement as the following:
$strSql = 'insert into results (vars) values (), (),()'
But the variables that fill the columns in MySql change troughout the simulation. Since I don't know how big the $auctionobjects variable will be, I cannot get the right number of brackets I need to fill in.
What I could do is create a variable that creates the string needed for the amount of $auctionobjects like this:
$createSqlString = '(vars)'
for($x = 0; $x< $auctionobjects; $x ++) {
$createSqlString .= ,(vars)
}
And then insert it in the Sql statement, but I am not sure if there is a more clean solution.