Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Problem with PostgreSQL >= v 1.8.1
  • I've got a problem with PostgreSQL queries and sessions (db driver -> postgres).

    I try to debug with very simple query:

    $sql = "SELECT * FROM users";
    $aUser = \DB::query($sql, \DB::SELECT)->execute()->current();

    var_dump($aUser) give me:

    On fuel/core 1.8.1.3 and below:

    /var/www/(....)/fuel/packages/myauth/classes/auth.php:46:
    array (size=6)
      'id' => int 0
      'login' => string 'somestring' (length=10)
      'pass' => null
      'name' => null
      'surname' => null
      'status' => int 0

    On fuel/core 1.8.1.4 and fuel/core 1.8.1.5:
    /var/www/(....)/fuel/packages/myauth/classes/auth.php:46:null

    The last version on which sessions work perfect was 1.8.0.4. Does anyone use postgres in projects and have the same problem ?
  • The only relevant commit in that period is https://github.com/fuel/core/commit/cd46fc6e4904354ecd2ab32ea6e2aaee15ab5027

    I assume you're using the standard PDO driver? I don't have PostgreSQL handy at the moment, but I can test with MariaDB, the result should be the same due to the PDO abstraction.

    Can you check if you have the above changes locally? Because that commit fixes exactly this issue (no data being returned).

    We run all our production apps on 1.9/develop, so for the moment I think that if there was a serious framework error, we would have noticed it by now?
  • I've got the latest commit locally. I try to check the operation on MariaDB / MySQL using the PDO and everything works correctly! So there is only problem with PostgreSQL.

    Please analyze the following queries and responses:

    $sql = "SELECT * FROM users";

    // MYSQL

    $aUser = \DB::query($sql, \DB::SELECT)->execute('mysql_test')->current();
    var_dump($aUser);

    ----
    /var/www/(...)/fuel/packages/myauth/classes/auth.php:41:
    array (size=6)
      'id' => string '1' (length=1)
      'login' => string 'test' (length=4)
      'password' => string 'hash_password' (length=13)
      'name' => string 'test' (length=4)
      'surname' => string 'TESTxxxTEST' (length=11)
      'status' => string '1' (length=1)
    ----

    $aUser = \DB::select()->from('users')->execute('mysql_test')->current();
    var_dump($aUser);

    ----
    /var/www/(...)/fuel/packages/myauth/classes/auth.php:45:
    array (size=6)
      'id' => string '1' (length=1)
      'login' => string 'test' (length=4)
      'password' => string 'hash_password' (length=13)
      'name' => string 'test' (length=4)
      'surname' => string 'TESTxxxTEST' (length=11)
      'status' => string '1' (length=1)
    ----

    // POSTGRESQL

    $aUser = \DB::query($sql, \DB::SELECT)->execute()->current();
    var_dump($aUser);

    ----
    /var/www/(...)/fuel/packages/myauth/classes/auth.php:51:null
    ----

    $aUser = \DB::select()->from('users')->execute()->current();   
    var_dump($aUser);

    ----
    /var/www/(...)/fuel/packages/myauth/classes/auth.php:55:null
    ----

    $aUser = \DB::query($sql, \DB::SELECT)->execute();
    foreach ($aUser as $aDetail)
    {
        var_dump($aDetail);
    }

    ----
    /var/www/(...)/fuel/packages/myauth/classes/auth.php:61:
    array (size=6)
      'id' => int 1
      'login' => string 'test' (length=4)
      'password' => string 'hash_password' (length=13)
      'name' => string 'test' (length=4)
      'surname' => string 'TESTxxxTEST' (length=11)
      'status' => int 1
    ----
  • What object does execute() return?

    I don't understand why this can happen, PDO is PDO, there is no RDBMS specific code in the PDO driver, and PDO does the abstaction, all the driver does is do a PDO Fetch, which is the same for both PostgreSQL and MySQL?
  • I think I found a problem. In the above tests for Postgres I had the directive enable_cache=false; for MySQL I didn't have it at all (default is enable_cache=true). I noticed this checking for you what the execute () method returns :)

    For Postgres it was Fuel\Core\Database_PDO_Result object, and for MySQL Fuel\Core\Database_PDO_Cached. Try to switch enable_cache to false to check what happend in your projects.

    What exactly this option is for (enable_cache) ?
  • Hmm... That should still work, that was wat that last commit was about. Does that mean your MySQL test will also fail when you disable the cache?

    When you process the result. with cache false, one record is fetched from the result for every request to the result, with cache true, all records in the result are fetched immediately, and you iterate over the stored result.

    No cache takes less memory compared to cache (especially when the result sets are large), but with the case you have direct access, so you can see, fetch previous and next, restart at the beginning, etc.

Howdy, Stranger!

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

In this Discussion