Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
\Session_Db: db object stored in variable causing issue
  • Hello,
    I came across an issue with DB objects within \Session_Db:

    In the read() function line 107, the session record is being stored within the object.

    $this->record = \DB::select()->where(‘session_id’, ‘=’, $cookie[0])->from($this->config[‘table’])->execute($this->config[‘database’]);

    However the session record can’t be accessed in the write() function line 207

    $result = \DB::update($this->config[‘table’])->set($session)->where(‘session_id’, ‘=’, $this->record->get(‘session_id’))->execute($this->config[‘database’]);

    $this->record->get(‘session_id’) is always null and make the session update fail.
  • HarroHarro
    Accepted Answer
    Is this related to https://github.com/fuel/core/pull/2083 ?

    I see now it wasn't merged for some reason...
  • Does that mean you have this same problem and this PR fixes it?
  • It's a different problem, this PR doesn't fix. 
    It seems like previous DB object is not accessible if there is another DB call in between.
    Here's a snippet to reproduce the issue :

    $dbobject = \DB::select()->where('id', '=', 1)->from('table')->execute();
            
    // get() works fine
    var_dump($dbobject->get('id'));
    $otherdbcall = \DB::select()->where('id', '=', 2)->from('table')->execute();
            
    // get() return null
    var_dump($dbobject->get('id'));
  • That looks like a very serious issue. Hmmm.... I'll dive into it later today.
  • I can't reproduce it, with that exact snippet:
    /data/www/19develop/fuel/app/classes/controller/db.php:12:string '1' (length=1)
    /data/www/19develop/fuel/app/classes/controller/db.php:15:string '1' (length=1)
  • Thanks for looking into it @Harro

    I might have a configuration error, it's using php 5.6.28 and mysql 5.6.34.
    The db config file in the app folder look like this : 
    array(
        'default' => array(
            'type'          => 'PDO',
            'connection'  => array(
                'dsn'        => 'mysql:host=localhost;dbname=db',
                'username'   => 'test',
                'password'   => 'test',
                'hostname'   => 'localhost',
                'database'   => 'db',
                'persistent' => false,
                'compress'   => false,
            ),
            'identifier'   => '`',
            'table_prefix' => '',
            'charset'      => 'utf8',
            'collation'    => false,
            'enable_cache' => false,
            'profiling'    => false,
            'readonly'     => false,
        ),
    );

    Any ideas?
  • Other then I would use "mysql" instead of "PDO" (so Fuel knows to generate MySQL SQL instead of ANSI SQL) I don't see anything weird.

    What version of Fuel are you on?
  • I'm using Fuel dev-1.9/develop, I've tried mysql instead of pdo but I'm still having issue.
  • Weird, as I wrote, I can not reproduce it with your code as posted on the 18th.

    edit: I just noticed that I have "enable_cache" set to true, maybe that may play a part, I will do some further digging tonight.
  • Unfortunately Harro I can confirm this issue on my setup:

    1.9/develop, PHP7.2

            $tp = \DB::select('*')
                    ->from('product')
                    ->where('id','=',1)
                    ->execute();
           
            var_dump( $tp->get('name') );
            var_dump( $tp->get('name') );

    First one returns expected value, second is null.
    string(1) "a"
    NULL

    Bug is affecting both PDO and Mysqli drivers.


  • Think I've found it. Can you update your fuel/core and check again?
  • It looks like there is a problem with implementation of current() method, which is attepmting to fetch results each time get is accessed, and these details seems to be accessible only once.

    If I keep the result withing the object first time I access data it works for me as a solution.

    Will check the update in a sec.
  • I can confirm, everything is working as expected after recent update.
    Thank you Harro!
  • Thanks for the feedback. I'll merge it as an 1.8.1 hotfix tomorrow.
  • Thank you for a quick fix.

    PS.  your solution is much more elegant than mine :D

    PS2. Some small issue on the website. When you try to respond to a post on forum and you're not logged in, login popup pops, however its position is fixed to the top of the page, not viewport. This is problematic when we have longer page content. Took me couple of seconds to find it.

    Browser: FF Dev
  • Awesome! thanks for the fix.

Howdy, Stranger!

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

In this Discussion