• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call to undefined method mysqli_stmt::get_result()

#1
Question 
Hi,

I totally do not understand why I am getting the error "Call to undefined method mysqli_stmt::get_result()"  As I am not calling the function!!!

The record IS inserted, but I do not understand why I am getting the error. Any ideas?????  (full error attached).

PHP Code:
<?php namespace App\Models\User;

use 
CodeIgniter\Model;
use 
CodeIgniter\Database\Query;

class 
Register extends Model {
    
    public function 
registerUser ($vals) {
        
$db db_connect();
        
        
        
$pQuery $db->prepare(function($db) {
            
$sql "INSERT INTO user_register (salutation, first_name, last_name, telephone, email, password, question, answer, status, level, confirm, ip) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";        
            return (new 
Query($db))->setQuery($sql);
        });
        
        try {    
            
$pQuery->execute(
            
$vals['salutation'],
            
$vals['first_name'],
            
$vals['last_name'],
            
$vals['telephone'],
            
$vals['email'],
            
$vals['password_hash'],
            
$vals['question'],
            
$vals['answer_hash'],
            
$vals['status'],
            
$vals['level'],
            
$vals['confirm'],
            
$vals['ip']
            );
        }catch(\
Exception $e) {
            
print_r($e);
            
//$db->close();
            
return $e;
            
        }
        
    }



Attached Files
.txt   full_error.txt (Size: 7.44 KB / Downloads: 3)
Reply

#2
(06-15-2020, 06:03 AM)68thorby68 Wrote: Hi,

I totally do not understand why I am getting the error "Call to undefined method mysqli_stmt::get_result()"  As I am not calling the function!!!

The record IS inserted, but I do not understand why I am getting the error. Any ideas?????  (full error attached).

PHP Code:
<?php namespace App\Models\User;

use 
CodeIgniter\Model;
use 
CodeIgniter\Database\Query;

class 
Register extends Model {
    
    public function 
registerUser ($vals) {
        
$db db_connect();
        
        
        
$pQuery $db->prepare(function($db) {
            
$sql "INSERT INTO user_register (salutation, first_name, last_name, telephone, email, password, question, answer, status, level, confirm, ip) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";        
            return (new 
Query($db))->setQuery($sql);
        });
        
        try {    
            
$pQuery->execute(
            
$vals['salutation'],
            
$vals['first_name'],
            
$vals['last_name'],
            
$vals['telephone'],
            
$vals['email'],
            
$vals['password_hash'],
            
$vals['question'],
            
$vals['answer_hash'],
            
$vals['status'],
            
$vals['level'],
            
$vals['confirm'],
            
$vals['ip']
            );
        }catch(\
Exception $e) {
            
print_r($e);
            
//$db->close();
            
return $e;
            
        }
        
    }

The docs say that $query->execute(); returns a result set, which is why the get_result() is being called.

You could do this using:
PHP Code:
class Register extends Model {
    protected $table 'user_register';
    public function registerUser($vals) {
        $this->db->insert($vals);
    }

Reply

#3
Thank you Ryan, but I need to use prepared queries as I have a number of queries that update multiple tables. Therefore a rollback option is preferable going forward.

And yes the documentation says (and if you follow the error, you can see) get_result() is being called. But why, if you follow the documentation and run the prepared query to spec, does get_result() give an error?

I would understand errors if the function was called incorrectly, but when executing the prepared query to spec I would not expect this to happen. And, I have tried every which way, using all of the example types.

I can only really conclude that either prepared queries DO NOT WORK, or the documentation is WRONG.

This said, many thanks for your suggestion.
Reply

#4
For everyone coming directly into this thread (answered this question in another thread by OP).

mysqli_stmt_get_result are only available with mysqlnd driver.

CodeIgniter 4 - Server Requirements
Reply

#5
Sorry jreklund. This doesnt make sense.

The ci4 prepared query implicitly calls mysqli_stmt_get_result. This is not something explicitly called in my code.

Therefore I'm assuming there is something wrong with the ci4 prepared query or (as I am executing to the letter of the documentation) I am totally missing the point (which is not rare!).

and I have checked my php config: mysqlind is alive and well :-) (attached)


Attached Files Thumbnail(s)
   
Reply

#6
mysqli_stmt_get_result get's called by execute, so that you get access to the result object, based on your prepared statement.
Reply

#7
You need to disable mysqli and enable nd_mysqli instead. It's under a different name with Cpanel, because reasons.
Reply

#8
sorry I might be a bit stupid here. But when I run execute in the prepared query I get error "Call to undefined method mysqli_stmt::get_result()"

so my thinking is:
My server meets the requirements
my data is good
I have prepared statement as per docs
I have executed the statement as per the docs

But execute is generating the error, and for the life of me I dont know why? :-)

The prepared query is erroring out on itself? Not becuase i'm get_results() explictly or i'm calling get_results() incorrectly.
Reply

#9
As it currently stands, your server does not meet the requirements. mysqli don't include all features, nd_mysqli does.
nd_mysqli where added as a replacement for mysqli, so that compatibility could be kept with older PHP versions.

https://cloudlinux.zendesk.com/hc/en-us/...D-vs-MySQL-
Reply

#10
Thank you so much.

I have updated my server...

I had to disable:
mysqli
pdo_mysqli

and enable
nd_mysqli
ng_pdo_mysqli

I am hopeful this will also iron out other issues I have been experiencing across the framework, and if it does I will update the approriate threads.

Not wanting to sound like a broken record, but some reference to this in the documentation would have saved me a couple of days, and you having to read/reply my boring threads.

Again, many thanks for your help and patience.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.