0

I am trying to convert a mysql script to mysqli and have hit a wall. I am trying to convert a mysql_result to mysqli however am unsure how to do this, below is my code

$_SESSION['num_user'] = mysql_result(mysqli_query($GLOBALS["___mysqli_ston"], "SELECT COUNT(*) FROM `members` WHERE mem_emailactivated = 1"), 0);
jhetheringt7
  • 191
  • 1
  • 1
  • 7

2 Answers2

2

As weird as it is, there doesn't seem to be a way to fetch without prepare/execute.

$stmt = mysqli_prepare($GLOBALS['___mysqli_ston'], "SELECT COUNT(*) AS count ...");
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $count);
mysqli_stmt_fetch($stmt);
$_SESSION['num_user'] = $count;
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
-1

You are mixing things up here. You wouldn't use mysql_result to get the result from a query using mysqli. you would instead use mysqli to iterate through the returned array and then store this array in the $_SESSION.

$result = $mysqli->query("call getUsers()");
if($result){
     // Cycle through results
    while ($row = $result->fetch_object()){
        $user_arr[] = $row;
    }

    $result->close();
}

$_SESSION['num_user'] = $user_arr;
What have you tried
  • 11,018
  • 4
  • 31
  • 45