3

Running PHP 8. I have just upgraded CodeIgniter from 3.0.4 to 3.1.13.

Before the upgrade, the affected_rows() worked fine and gave me the correct quantity.

Now it just gives me a TypeError.

This is a little above my head but I've tried to understand the ODBC driver. I think it's because _execute() returns a boolean, but odbc_num_rows() crashes because it expects a resource.

Any suggestions to fix this?

4
  • maybe this will point you in the right direction: stackoverflow.com/questions/11536077/… Commented Nov 17 at 19:34
  • @Vickel Unfortunately not, but thanks anyway :) Commented Nov 18 at 7:55
  • What is the error message and what is your sequence of calls? _execute() was changed between your versions. If $this->odbc_result isn't set you should get the same result as before. But if odbc_num_rows() gets a boolean, then the query from before didn't worked, see line 227 of CI_DB_odbc_driver where this method returns false in case $this->odbc_result === FALSE. Fix it and affected_rows() should work without a type error. Commented Nov 18 at 9:41
  • @1stthomas Thank you for your answer. The query actually works and the method returns true, but that still gives a type error in php 8 because odbc_num_rows() expects a resource. It's not only the error that is a problem. I need the actual count of updated rows, not just true or false. Anyway, I found a fix for my problem and will post it as an answer. Commented Nov 18 at 11:18

1 Answer 1

2

I compared the old execute() function (system/database/drivers/odbc/odbc_driver.php) with the updated version and found the culprit. $this->is_write_type($sql) OR $success = $this->odbc_result; returns a boolean for all writes to the db.

In the old version they just returned whatever odbc_exec() gave.

To fix this, I just removed the first part of $this->is_write_type($sql) OR $success = $this->odbc_result; and only kept $success = $this->odbc_result;. This may cause problems if some other code expects a boolean and make a strict check for === true.

I hope this made any sense. If someone has a better solution, please tell me.

Sign up to request clarification or add additional context in comments.

1 Comment

That sounds a bit as if you've found a bug in the code. You should report your issue and discuss your findings with the developers of that code. As you rightfully have mentioned, the fix is early and it won't make always sense, so it requires more discussion on the development level - which can't be practically done here on SO finally. What you describe sounds like it needs to be addressed in the library material -- or not using the library (which IIUC is not what you want to do.) Hope that helps. And don't forget to mark your question answered as you came to a conclusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.