-
Which one is faster?
Hi,
I have a simple Q: Which one is faster?
PHP Code:
<?php
error_reporting(0);
ini_set('display_errors', '0');
require_once 'adodb_lite/adodb.inc.php';
if (!isset($_GET['q']) || (!$q=$_GET['q'])) {
exit();
}
$db = ADONewConnection('mysql');
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if (!$rt = $db->PConnect('localhost', 'test', 'test', 'autocomplete')) {
exit();
}
if (!$rs = $db->Execute('SELECT v FROM ac WHERE v LIKE "%'.addslashes($q).'%"')) {
exit();
}
while (!$rs->EOF) {
echo $rs->fields[0],"\n";
$rs->MoveNext();
}
?>
vs
PHP Code:
<?php
error_reporting(0);
ini_set('display_errors', '0');
require_once 'adodb_lite/adodb.inc.php';
if (isset($_GET['q']) && ($q=$_GET['q'])) {
$db = ADONewConnection(DB_TYPE);
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($rt = $db->PConnect('localhost', 'test', 'test', 'autocomplete')) {
if ($rs = $db->Execute('SELECT v FROM ac WHERE v LIKE "%'.addslashes($q).'%"')) {
while (!$rs->EOF) {
echo $rs->fields[0],"\n";
$rs->MoveNext();
}
}
}
}
?>
Thanks,
-
The first is theoretically just slightly faster, but so little you wouldn't notice. It's easy to test. But the first is also bad practice in general. It's best to have complete code without various exits throughout.