I have two versions of code to do the same thing. One uses prepared statements, the other concatenated strings. My understanding is that the prepared statements should result in a performance increase, but after setting $size=100 (therefore iterating the code for 10000 insert queries), I haven't been able to detect any difference in performance between the two methods. Each runs in appx. 133 seconds. Am I implementing the prepared statement code incorrectly? Code follows:
Prepared Statements:
if ($stmt = $mysqli->prepare("INSERT INTO sectors (sector) VALUES (?)"))
{
for ($x = 0; $x < $size; ++$x)
{
for ($y = 0; $y < $size; ++$y)
{
$dirtysector = $x . "-" . $y;
$secstring = clean_sector($dirtysector);
$stmt->bind_param('s', $secstring);
$stmt->execute();
}
}
$stmt->close();
Concatenated Strings:
for ($x = 0; $x < $size; ++$x)
{
for ($y = 0; $y < $size; ++$y)
{
$dirtysector = $x . "-" . $y;
$secstring = clean_sector($dirtysector);
$query = "INSERT INTO sectors " .
"(sector) VALUES " .
"('$secstring')";
$result = $mysqli->query($query);
if(!$result) die("Sector Creation Failed: " . $mysqli->error);
}
}