Hi, i am trying to make this work but i guess i am missing something.....
This is what i have:
"db.php"
<?php
DEFINE('DATABASE_USER', 'root');
DEFINE('DATABASE_PASSWORD', '123456');
DEFINE('DATABASE_HOST', 'localhost');
DEFINE('DATABASE_NAME', 'livesearch');
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
else {
//connected
}
?>
"test.php"
<?php
class article {
function getArticles()
{
$query = "
SELECT *
FROM topics
WHERE topictitle like '%$keyword%' or topicdescription like '%$keyword%';
";
if ($result = $mysqli->query($query) )
{
while ($row = $result->fetch_assoc()) {
echo $row['topictitle'].'<br>';
echo $row['topicdescription'].'<br><br>';
}
$result->close();
}
}
}
include 'db.php';
$Article = new article($mysqli);
$Article->getArticles();
?>
The error I am getting is:
"Fatal error: Call to a member function query() on a non-object in C:\AppServ\www\test.php on line 13"
This line is not working:
if ($result = $mysqli->query($query) )
I don't know how to pass the $mysqli into the class and then into the function....... PLEASE HELP