We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3496
    • 101 Posts
    Hi,
    I’m migrating some of my own PHP code to MODx revolution, but something goes wrong in a query - to one of my own tables.
    I am still using the db API (in this case: db->getValue).

    The error I get (in firebug) is the following:
    E WARNING: PDO::query() expects parameter 1 to be string, object given.

    Some of the detailed information:
    C:\Data\webdev\modx-fyp\core\xpdo\xpdo.class.php
    1737
    trigger_error()

    C:\Data\webdev\modx-fyp\core\model\modx\dbapi.class.php
    147
    xPDO->query( PDOStatement(’queryString’=>’SELECT eorder FROM eigens...1" ORDER BY eorder DESC ’))

    C:\Data\webdev\modx-fyp\core\model\modx\dbapi.class.php
    450
    DBAPI->query( PDOStatement(’queryString’=>’SELECT eorder FROM eigens...1" ORDER BY eorder DESC ’))

    C:\Data\webdev\modx-fyp\assets\beheer\prodHandling.php
    443
    DBAPI->getValue( PDOStatement(’queryString’=>’SELECT eorder FROM eigens...1" ORDER BY eorder DESC ’))

    The full query: ’SELECT eorder FROM eigenschap WHERE ecid="1" ORDER BY eorder DESC ’

    Some environment information:
    Windows, XAMPP-win32-1.7.3
    (Apache 2.2.14, MySQL 5.1.41 + PBXT engine, PHP 5.3.1)

    Is this a bug, or did I do something wrong?
      • 22303 MODX Staff
      • 10,725 Posts
      I’m not following the detailed info you have posted or how it was generated. Can you simply post your code that uses the DBAPI?
        • 3496
        • 101 Posts
        Hello Open Geek,

        Thanks for your response.

        See attachment for a relevant part of the code.

        In trying to give you the relevant part of the code I found out that the problem has something to do with my use of firephp for debugging.

        If the following three lines are removed from the code, getValue works as it should:
        $firephp->registerErrorHandler($throwErrorExceptions=TRUE);
        $firephp->registerExceptionHandler();
        $firephp->registerAssertionHandler($convertAssertionErrorsToExceptions=TRUE,$throwAssertionExceptions=FALSE);

        But getRow works fine in both situations.

        Perhaps I should go for a different debugging solution...

        Best regards,
        Marco (Black Raven)
          • 22303 MODX Staff
          • 10,725 Posts
          Revo provides default and allows custom error_handlers; it also includes logging functionality that can be directed to file, output to the pages, or to a modRegister instance. See modX::log() and related functions for this.

          Unfortunately I’m not personally familiar with FirePHP, but I bet a modRegister instance could be authored to integrate it so that you get custom and core debug info logged in one convenient place using the modX::log() function.

          If I get time I’ll look into what the conflict may be.
            • 3496
            • 101 Posts
            Ok; thanks!
              • 3496
              • 101 Posts
              OpenGeek,
              Did you already find some time to look into this issue?
              (would be a miracle with all the other things you’re doing, but one can always hope...)
                • 22303 MODX Staff
                • 10,725 Posts
                No, unfortunately I am pretty swamped atm. If someone with FirePHP experience could assist, that’d be wonderful.
                  • 3496
                  • 101 Posts
                  Ok; thanks for all the good work! (I’m afraid I just use firephp; I don’t know how it works...)

                  For further information:
                  I am (again) trying to get my PHP code working in the Revolution environment, now without any firephp calls, but I have more or less given up on the DB API.
                  I now just continuously test my PHP code - get an error or warning on some DB API call - and replace that call by an xPDO call. I have been doing that for the last two days and I still have a lot of database-interaction to go, but I’m getting there...
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: Black at Jun 15, 2010, 10:35 AM

                    Ok; thanks for all the good work! (I’m afraid I just use firephp; I don’t know how it works...)

                    For further information:
                    I am (again) trying to get my PHP code working in the Revolution environment, now without any firephp calls, but I have more or less given up on the DB API.
                    I now just continuously test my PHP code - get an error or warning on some DB API call - and replace that call by an xPDO call. I have been doing that for the last two days and I still have a lot of database-interaction to go, but I’m getting there...

                    Hmmm, can you give me an example of the DBAPI calls and errors? The intention is that most would still work as they would in Evo and it might be worth fixing to ease migration pains for others.
                      • 3496
                      • 101 Posts
                      No problem, see below for two examples.
                      Example 1:
                      Code:
                      $where='ipi.icecatid=ic.icecatid AND catid='.$this->_catid .
                             ' AND ipi.copydate>'.strftime('%Y%m%d', Time()-(10*24*3600));
                      $result=$this->_mymodx->db->select('ipi.copytotal', 'fyp_icecategory as ic, fyp_iceproductindex as ipi', $where);	
                      if (!$this->_mymodx->db->getRecordCount($result)) return FALSE; // IF no results: return FALSE	
                      $total = $this->_mymodx->db->getValue($result);

                      Error:
                      [2010-06-15 21:54:03] (ERROR @ C:\Data\webdev\modx-fyp\core\xpdo\xpdo.class.php : 1796) PHP warning: PDO::query() expects parameter 1 to be string, object given
                      [2010-06-15 21:54:03] (ERROR @ C:\Data\webdev\modx-fyp\core\model\modx\dbapi.class.php : 149) Recoverable error: Object of class PDOStatement could not be converted to string
                      [2010-06-15 21:54:03] (ERROR @ /index.php) Execution of a query to the database failed: 
                      Array
                      (
                          [0] => 00000
                          [1] => 
                          [2] => 
                      ) 


                      Example 2:
                      Code:
                      $r = $this->_mymodx->db->insert(array('plnaam'=>$this->_mymodx->db->escape($plnaam), 
                      	'catid'=>$catid, 'mid'=>$mid), 
                      	'fyp_productlijn');

                      Warning:
                      [2010-06-15 22:28:09] (WARN @ C:\Data\webdev\modx-fyp\core\model\modx\dbapi.class.php : 259) PHP notice: Undefined variable: sql


                      This last warning I have seen many times.

                      Is this enough information?