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'].''; echo $row['topicdescription'].'
'; } $result->close(); } } } include 'db.php'; $Article = new article($mysqli); $Article->getArticles(); ?>
The error i get 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 dont now how to pass the $mysqli into the class and then into the fuction… PLEASE HELP