0

So this is the code that's causing a headache at this time. Getting this error:

Fatal error: Call to undefined method mysqli_result::execute()

Not sure where I've done it wrong at:

$mysqli_load = new mysqli(HOST, USER, PASS, DB);
$query = 'SELECT `id`, `call_taker`, `call_time`, `call_type`, `call_priority`, `call_location`, `call_city`, `reporter_name`, `reporter_num`, `call_info` FROM `calls`';
$sql = mysqli_query($mysqli_load, $query) or die($mysqli_load->error);
$sql->execute() or die($mysqli_load->error);
$sql->bind_result($c_id, $c_taker, $c_time, $c_type, $c_priority, $c_location, $c_city, $r_name, $r_num, $c_info) or die($mysqli_load->error);
while($row = mysqli_fetch_assoc($sql)){
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

mysqli_query is returning mysqli_result object, which has methods for manipulating result of query like fetch, fetch_object, etc as it is a result. Query has already been executed at this point.

The usage of mysqli::bind_result is at wrong place, it should be run on statement. And should be avoided altogether as it was removed in PHP5.4.

What about formulating it this way:

$mysqli_load = new mysqli(HOST, USER, PASS, DB);
$query = 'SELECT `id`, `call_taker`, `call_time`, `call_type`, `call_priority`, `call_location`, `call_city`, `reporter_name`, `reporter_num`, `call_info` FROM `calls`';
$sql = mysqli_query($mysqli_load, $query) or die($mysqli_load->error);

while ($row = mysqli_fetch_assoc($sql)) {
    // data manipulation
}

// and possibly close connection

No need to executing and binding anything.

For future reference, if your queries will take some user input, take at look at How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
Michal Brašna
  • 2,293
  • 13
  • 17