I don't think that performance is a compelling argument either way. On my Mac, I ran the following tests.
First 10,000 includes of a file that doesn't do anything but set a variable:
<?php
$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
for ($i = 0; $i < 10000; $i++) {
include("foo.php");
}
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo 'Rendered in ' .$totaltime. ' seconds.';
?>
It took about .58 seconds to run each time. (Remember, that's 10,000 includes.)
Then I wrote another script that queries the database 10,000 times. It doesn't select any real data, just does a SELECT NOW()
.
<?php
mysql_connect('127.0.0.1', 'root', '');
mysql_select_db('test');
$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
for ($i = 0; $i < 10000; $i++) {
mysql_query("select now()");
}
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo 'Rendered in ' .$totaltime. ' seconds.';
?>
This script takes roughly 0.76 seconds to run on my computer each time. Obviously there are a lot of factors that could make a difference in your specific case, but there is no meaningful performance difference in running MySQL queries versus using includes. (Note that I did not include the MySQL connection overhead in my test -- if you're connecting to the database only to get the included data, that would make a difference.)