PHP SQLite3 Database fetchArray error

Hey guys, if anyone could, I desperately need some help. I asked for help on another forum, but when I didn’t understand their answers they didn’t take it too kindly.

Basically I’ve been working on this project for far longer than needed (I’m actually embarrassed to admit how long) And it’s a really odd one. Our goal is to make a site that contains 3 sqlite database tables and links them together in a way. My site just has a simple function of storing website names and user info for them like password hints or categories, which the user can then search for on another page - Either by searching site by name, category or both.

PROBLEM: No matter what way I try to get data from the database, it always gives me an error like:

Fatal error: Call to undefined method SQLite3Result::fetch_array() in C:\xampp\htdocs\Projects\FinalProject\You_Shall_Pass_UserHome.php on line 34

And I honestly can’t figure out why. I’ve tried rearranging the code in various ways, but I can’t get it to output - Which is frustrating because I’ve succeeded in searching the database before and then returning a vardump, but I can’t repeat it again. The code basically calls one of 3 functions to know what to search, and then is supposed to return the data in a table format.

I’m really really lost at this point though. If anyone could please help me, I’d be so grateful. I just want to finally finish this.

Code that calls functions and is supposed to display data in a table:
[php] // Decides on how to search database based on user input
if(!empty($_POST[‘searchName’]) && !empty($_POST[‘searchCate’]))
{
$output = bothQuery();
}
elseif(isset($_POST[‘searchName’]))
{
$output = nameQuery();
}
elseif(isset($_POST[‘searchCate’]))
{
$output = cateQuery();
}

if(isset($output))
{
	echo "<table>";
	
	while($row = $output->fetchArray())
	{
		echo "<tr><td>" . $row['siteName'] . "</td><td>" . $row['pass'] . "</td><td>" . $row['category'] . "</td></tr>";
	}
	
	echo "</table>";
}[/php]

And these are the functions themselves, I’ll mark line 34, the error source (I’ve made several changes to it and other methods I’ve used to try and get the table data, but a similar error always shows up)

[php] // Functions to sort data based on input
function bothQuery()
{
$db = new MyDB();
$login = $_SESSION[‘user’];
$nameEntered = $_POST[‘searchName’];
$cateEntered = $_POST[‘searchCate’];

	$id = $db->query("SELECT idUser FROM user WHERE name = '$login'");
	
	 while ($row = $id->fetch_array(SQLITE_ASSOC))  // LINE 34
	 { 
	 $testID = $row['idUser'];
	$result = $db->query("SELECT siteName FROM sites s JOIN siteInfo i ON s.idSite
								= i.idSite WHERE idUser = '$testID' AND siteName = '$nameEntered' 
								AND category = '$cateEntered'");
		while($row = $result->fetchArray())
		{
		return $row;
		}
	}
}

function nameQuery()
{
	$db = new MyDB();
	$login = $_SESSION['user'];
	$nameEntered = $_POST['searchName'];
	
	$id = $db->query("SELECT idUser FROM user WHERE name = '$login'");
	$result = $db->query("SELECT siteName FROM sites JOIN siteInfo ON idSite
								= idSite WHERE idUser = '$id' AND siteName = '$nameEntered'");
	return var_dump($result);
}

function cateQuery()
{
	$db = new MyDB();
	$login = $_SESSION['user'];
	$nameEntered = $_POST['searchName'];
	$cateEntered = $_POST['searchCate'];
	
	$id = $db->query("SELECT idUser FROM user WHERE name = '$login'");
	$result = $db->query("SELECT siteName FROM sites JOIN siteInfo ON idSite
								= idSite WHERE idUser = '$id' AND category = '$cateEntered'");
	return $result;
}[/php]

Try removing the underscore.

[php]
while ($row = $id->fetch_array(SQLITE_ASSOC))[/php]
[php]while($row = $result->fetchArray())[/php]

fetchArray

Sponsor our Newsletter | Privacy Policy | Terms of Service