tags:

views:

41

answers:

3

I keep getting the following error listed below and I was wondering how do I correct this error.

Warning: mysqli_close() expects exactly 1 parameter, 0 given in

Here is the code listed below.

<?php
require_once ('./mysqli_connect.php'); // Connect to the db.

function make_list ($parent) {

 global $tasks;

 echo '<ol>';

 foreach ($parent as $task_id => $todo) {

  echo "<li>$todo";

  if (isset($tasks[$task_id])) { 

   make_list($tasks[$task_id]);

  }

  echo '</li>';

 } // End of FOREACH loop.

 // Close the ordered list:
 echo '</ol>';

} // End of make_list() function.

 $mysqli = new mysqli("localhost", "root", "", "sitename");
 $dbc = mysqli_query($mysqli,"SELECT task_id, parent_id, task FROM tasks WHERE date_completed='0000-00-00 00:00:00' ORDER BY parent_id, date_added ASC");
if (!$dbc) {
 // There was an error...do something about it here...
 print mysqli_error();
} 

$tasks = array();

while (list($task_id, $parent_id, $task) = mysqli_fetch_array($dbc, MYSQLI_NUM)) {

 // Add to the array:
 $tasks[$parent_id][$task_id] =  $task;

}

make_list($tasks[0]);


mysqli_close(); // close the connection

// Include the html footer
include('./includes/footer.html');
?>
+6  A: 

The error message is clear : you called mysqli_close without any argument, while the function expects one.

According to mysqli_close documentation, you must provide the mysqli link as its argument.

Sylvain
How do I do this?
sawu
you get an object representing the connection to the database when you connect to it.Using the procedural way, it may looks like this:$link = mysqli_connect("localhost", "user", "passwd", "db");mysqli_close($link);The OO way may looks like this:$mysqli = new mysqli("localhost", "user", "passwd", "db");and$mysqli->close();
Sylvain
+1  A: 

Call mysqli_close($mysqli);

Evän Vrooksövich
+1  A: 

Use $mysqli->close(); or mysqli_close($mysqli);