Welcome Guest, Not a member yet? Register   Sign In
CI3 num_rows on CI4
#11

There is indeed something wrong. After following the instructions in the manual, https://www.codeigniter.com/user_guide/d...sults.html, code below, the following error message is sent:
"Undefined property: CodeIgniter\Database\MySQLi\Result::$getRow"
PHP Code:
$id 123;
    $query $db->table('names')
    -> where('id'$id)
    -> get();

    $row $query->getRow;

    if (isset($row)) {
        echo $row->name;
    
CodeIgniter Version: 4.1.9
If plan A fails, relax... the alphabet is 26 letters
Reply
#12

I believe you forgot the parenthesis on the getRow() statement.

From what I can understand the OP isn't complaining that it isn't working. He's complaining his Visual Code editor is highlighting it as an error, which is why I asked if he has the relevant extensions installed for CI4. I haven't checked though. to be honest.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#13

I apologize, I didn't notice the lack of parentheses, after the change it worked without problems.
If plan A fails, relax... the alphabet is 26 letters
Reply
#14

(03-30-2022, 10:50 AM)ignitedcms Wrote: I believe you forgot the parenthesis on the getRow() statement.

From what I can understand the OP isn't complaining that it isn't working. He's complaining his Visual Code editor is highlighting it as an error, which is why I asked if he has the relevant extensions installed for CI4. I haven't checked though. to be honest.
I do not have dedicated extensions for CI4, for php I only have intelephense, I have to do some tests, but I think the problem lies in the order in which the code in the method is executed, in my specific case the code is more complex than the example I have posted, because I was trying to figure out which was the real replacement for the nums_rows function because in various other posts different things are listed and I had created a lot of confusion
Reply
#15

Ok, i took a test

PHP Code:
$query $this->db->table('table')
            ->select('field')
            ->where('id_record'$id)
            ->limit(1)
            ->get();

        $result $query->getRow();

        $rows $query->getNumRows(); 

So everything works, but VS Code with php intelephense extension, report error on getNumRows() -> undefined method, I don't know why but if it happens to someone else the problem is here
Reply
#16

I tested this in Visual Studio Code too where I have installed the 'Intelephense' extension as part of the 'Codeigniter 4 Extension Pack' by Rade Reksi Susanto.
Code:
$rows = $query->getNumRows(); 

is indeed marked as an error, which probably means that Inteliphense doesn't know the method. You shoud report it as an issue on the developers Github.
Reply
#17

With PhpStorm, there is no problem. It seems a bug in VS Code extentions.
[Image: 2022-04-05-10-34-04.png]
Reply
#18

I believe it is a matter of semantics. I did the test using a real table, in VScode and using real data and it worked, because the result is displayed, however, as @JustJohnQ said Inteliphense does not recognize the method.
So although the method is not recognized, it works!

PHP Code:
echo '<pre>';
    $id 28;    
    $query 
$db->table('names')
    -> where('id'$id)
    -> get();

    $result $query->getRow();

    $rows $query->getNumRows();    

    
echo $rows;
    echo '<p>';
    print_r($result); 


[Image: aMwMb45J_t.jpg]
If plan A fails, relax... the alphabet is 26 letters
Reply




Theme © iAndrew 2016 - Forum software by © MyBB