function searchMySQL($db, $q, $r, $o, $s, $c) {
global $config;
$server = $db['server'];
$port = $db['port'];
$username = $db['username'];
$password = $db['password'];
$database = $db['database'];
$tables = $db['table'];
$tableAssoc = $db['tableAssoc'];
$rfields = $db['returnField'];
$sfields = $db['searchField'];
$wildcard = strtolower($db['wildcard']);
$persistent = $db['persistent'];
$orderByDepth = $db['orderByDepth'];
$forceLower = $db['forceLower'];
$debug = $config['debug'];
$retVal = array();
if ($debug)
printf("-->Debug: searchMySQL()<BR>\n");
if (!function_exists('mysql_connect')) {
printf("MySQL support is not compiled into PHP.<BR>\n");
return $retVal;
}
if (strlen($server) < 1)
$server = 'localhost';
if ($port > 0)
$server = sprintf("%s:%d", trim($server), $port);
if ($debug)
printf("-->Debug: searchMySQL() - server: '%s', username: '%s', password: '%s'<BR>\n", $server, $username, $password);
if ($persistent)
$con = @mysql_pconnect($server, $username, $password);
else
$con = @mysql_connect($server, $username, $password);
if (!$con) {
printf("Error: Connection to MySQL server '%s' failed.<BR>\n", $server);
return $retVal;
}
if (!@mysql_select_db($database, $con)) {
printf("Error: Connection to MySQL database '%s' failed.<BR>\n>%s: %s<BR>\n", $database, @mysql_errno($con), @mysql_error($con));
return $retVal;
}
$statement = 'SELECT ';
$orderBy = ' ORDER BY ';
if ($s > 0 && $r > 0) {
$limit = ' LIMIT ';
if ($o > 0)
$limit .= sprintf('%d,%d', $o, $r);
else
$limit .= $r - ($c % $r);
}
$i = 0;
reset($rfields);
while (list(, $entry) = each($rfields)) {
$statement .= $entry;
if ($i < $orderByDepth || $orderByDepth < 0)
$orderBy .= $entry;
$i++;
if ($i < count($rfields)) {
$statement .= ', ';
if ($i < $orderByDepth || $orderByDepth < 0)
$orderBy .= ', ';
}
}
$statement .= ' FROM ';
$i = 0;
reset($tables);
while (list(, $entry) = each($tables)) {
$i++;
$statement .= $entry;
if ($i < count($tables))
$statement .= ', ';
}
$statement .= ' WHERE ';
if (strlen($tableAssoc) > 0)
$statement .= $tableAssoc . ' AND (';
$i = 0;
reset($sfields);
while (list(, $entry) = each($sfields)) {
$i++;
if ($forceLower) {
$statement .= 'LOWER(' . $entry . ')';
$q = strtolower($q);
} else {
$statement .= $entry;
}
if (!strcmp($wildcard, 'none')) {
$statement .= ' = \'';
} else {
$statement .= ' LIKE \'';
}
if (!strcmp($wildcard, 'left') || (strcmp($wildcard, 'right') && strcmp($wildcard, 'none')))
$statement .= '%';
$statement .= $q;
if (!strcmp($wildcard, 'right') || (strcmp($wildcard, 'left') && strcmp($wildcard, 'none')))
$statement .= '%';
$statement .= '\'';
if ($i < count($sfields))
$statement .= ' OR ';
}
if (strlen($tableAssoc) > 0)
$statement .= ') ';
if ($orderByDepth != 0)
$statement .= $orderBy;
if ($limit)
$statement .= $limit;
if ($debug) {
printf("-->Debug: searchMySQL() - MySQL statement: %s<BR>\n", $statement);
flush();
}
$query = @mysql_query($statement, $con);
if (!$query && $forceLower) {
if ($debug) {
printf("-->Debug: searchMySQL() - Statement failed using LOWER(), now attempting with LCASE().<BR>\n-->Debug: searchMySQL() - %s: %s<BR>\n", mysql_errno($con), @mysql_error($con));
}
str_replace('LOWER', 'LCASE', $statement);
$query = @mysql_query($statement, $con);
}
if (!$query) {
printf("Error: MySQL query '%s' failed.<BR>\n>%s: %s<BR>\n", $statement, @mysql_errno($con), @mysql_error($con));
return $retVal;
}
$width = count($rfields);
for ($row = 0; $row < $o - ($c % $r); $row++) /* Pad out results. We need a real fix. */
$retVal[$row][0] = 0;
while ($line = mysql_fetch_row($query)) {
for($i = 0; $i < $width; $i++) {
$retVal[$row][$rfields[$i]] = $line[$i];
}
$row++;
}
if (!$db['persistent'])
mysql_close($con);
return $retVal;
this is the function, it does not allow me to post the whole code because there is limit on the characters
anyway i hope this is enough, if not, will split the whole code in few posts