Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fuel 1.8.2 PHP 7.3.11 query
  • Hi all,

    I'm upgrading my fuel app, I've hit an issue with my custom OCI DB driver, I did have to refactor it slightly, but the structure of the result object does not appear to have changed between the old codebase & new

    object(Fuel\Core\Database_OCI_Result)#85 (8) {
      ["_query":protected]=>
      string(538) "SELECT 
    `omitted`
      ["_result":protected]=>
      array(1) {
        [0]=>
        object(stdClass)#56 (29) {
          ["id"]=>
          string(8) "test"
        }
      }
      ["_results":protected]=>
      NULL
      ["_row":protected]=>
      NULL
      ["_total_rows":protected]=>
      int(1)
      ["_current_row":protected]=>
      int(-1)
      ["_as_object":protected]=>
      bool(true)
      ["_sanitization_enabled":protected]=>
      bool(false)
    }

    Why can't I access this data via $data[0] ? -this worked previously

    If I loop through the single array index, it will work, but I can't manually access it via the above

    Error [ Error ]:
    Cannot use object of type Fuel\Core\Database_OCI_Result as array

    Thanks in advance
  • Harro VertonHarro Verton
    Accepted Answer
    I can't look into your code, but there are two result objects: a standard one, and a cached one.

    The standard one doesn't cache anything, but simply fetches the next row from the result as you iterate over it. This implies there is no random access, you can only loop once, start to finish.

    The cached one, as its name implies, fetches all rows at one and stores it internally. This means random access is possible. To to that, it implements SeekableIterator and ArrayAccess.

    If you come from an older Fuel version, you might have to update your code as quite a bit has changed here. Look at the PDO 'cached.php' and 'result.php' files for reference.
  • Thanks Harro,

    It looks like my old code did return 

    new \Database_Result_Cached($result, $sql, $as_object);

    And now I'm returning Database_OCI_Result which extends \Database_Result

    So that must be where I'm going wrong, thanks!
  • Database_Result_Cached no longer exists.

    You need to have two classes, Database_OCI_Result (non-cached), and Database_OCI_Cached (cached).

    Just take the two MySQL (if you're using PDO) or the two MySQLi classes (if you don't) as an example.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion