Reputation: 6338
Why am I getting the error:
Fatal error: Call to undefined method mysqli::fetch_object()
Heres my code:
$mysqli = new mysqli($db_data_hostname, $db_data_username, $db_data_password, $db_data_dbname);
$query = "SELECT attName, attType, attOptions FROM form_constructor WHERE device_name='$deviceType';";
$result = $mysqli->query($query);
while($row = $mysqli->fetch_object($result)){
echo $row->attName;
echo $row->attType;
echo $row->attOptions;
}
Upvotes: 0
Views: 2875
Reputation: 436
You should call fetch_object on the stmt result you get from $result. So your while loop would look like:
while($row = $result->fetch_object()) {
Upvotes: 3
Reputation: 2621
You have to use the mysqli result:
while($row = $result->fetch_object()){
echo $row->attName;
echo $row->attType;
echo $row->attOptions;
}
Upvotes: 2
Reputation: 11375
Why are you getting the error?
You need to use the variable $result
which has $mysqli->query
assigned to it. Read about MySQLi Object approach on the manual
Your code, fixed.
$mysqli = new mysqli($db_data_hostname, $db_data_username, $db_data_password, $db_data_dbname);
$query = "SELECT attName, attType, attOptions FROM form_constructor WHERE device_name='$deviceType';";
$result = $mysqli->query($query);
while($row = $result->fetch_object()){
echo $row->attName;
echo $row->attType;
echo $row->attOptions;
}
Upvotes: 4