I've got a database searchscript with a simple SELECT-query that works nicely with one database. But, when I try to make it search against another database it returns no results at all. Database hostname/user/password/db-name/table-name and field-names have of course been changed accordingly.
It seems like the php search-script halts just as it enters the for loop statement, since all that's showing on the searchresult-page is "The following results were found".
Perhaps I should mention that the "problem"-database were created with an old version of php/mysql (3.23), while the search-script and the "working" database were created using the latest version of php/mysql. You may notice that the search script uses mysqli statements which were NOT supported prior to mysql 4.1. After upgrading from mysql 3.23 to mysql 5.0.51a, I imported the sql-dump created in 3.23 to 5.0.51a. Could this be the problem?
The php code seems fine though, and I get no error-messages.
Here's the code:
@ $db = new mysqli('localhost', 'username', 'password', 'database');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database.';
exit;
}
$query = "SELECT * FROM tbl_product WHERE ".$searchtype." LIKE '%".$searchterm."%'";
$result = $db->query($query);
$num_results = $result->num_rows;
echo "<p>The following results were found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<br />ISBN: ";
echo stripslashes($row['pd_isbn']);
echo "</strong><br />Author: ";
echo stripslashes($row['pd_author']);
echo "<p><strong>".($i+1).". Title: ";
echo htmlspecialchars(stripslashes($row['pd_title']));
echo "<br />Price: ";
echo stripslashes($row['pd_price']);
echo "</p>";
echo "</p>";
}