1

So for some reason when I use the = operater in my prepared statement there is no problem however when I use the below operator ( < ) it gives an error.

mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given.

So I know mysql gives false if there is a problem with my query. however I cant see the problem.

function availableapps($security)
{
    if(empty($databasemanager)) { $databasemanager = new databasemanager(); }
    $db = $databasemanager->connectionstring();

    $result = $db->prepare("SELECT name FROM applications Where security<?");
    $result->bind_param("s", $security);
    $result->execute();

    $types = array();
    while(($row =  mysqli_fetch_assoc($result->get_result()))) {
        $types[] = $row['name'];
    }

    $result->close();

    return $types;
}

Just for demonstration purposes, final working code:

    function availableapps($security)
{
    if(empty($databasemanager)) { $databasemanager = new databasemanager(); }
    $db = $databasemanager->connectionstring();

    $result = $db->prepare("SELECT name FROM applications Where security<?");
    $result->bind_param("s", $security);
    $result->execute();
    $results = $result->get_result();

    $types = array();
    while($row =  $results->fetch_assoc()) {
        $types[] = $row['name'];
    }

    $result->close();

    return $types;
}

1 Answers1

0
while ($row = $result->fetch_assoc()) {
Mihai
  • 26,325
  • 7
  • 66
  • 81
  • This did the trick however I first needed to figure out you also had to use the get_result. –  Apr 17 '14 at 12:56