We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3496
    • 101 Posts
    Does anyone know what the following warning means?
    ’...dbapi.class.php : 259) PHP notice: Undefined variable: sql ’

    (I get this warning a lot)
      • 28215
      • 4,149 Posts
      1. It’s probably a bug.
      2. Why are you using the DBAPI class in Revo?
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 3496
        • 101 Posts
        I’m using DB API because my code was originally written for Evolution.

        I am moving my database interaction to xPDO, but it takes some time (also because I’m pretty fluent in SQL, but not yet so practised in the xPDO logic).
          • 3749
          • 24,544 Posts
          Quote from: Black at Jun 14, 2010, 02:05 PM

          I’m using DB API because my code was originally written for Evolution.

          I am moving my database interaction to xPDO, but it takes some time (also because I’m pretty fluent in SQL, but not yet so practised in the xPDO logic).

          See if this helps get you started: http://bobsguides.com/revolution-objects.html

          You can often cut your lines of code dramatically with xPDO, especially using getObjectGraph() and getCollectionGraph().

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 3496
            • 101 Posts
            Thanks - your xPDO page has indeed been useful for me earlier already.

            At the moment my xPDO statement seem to take more lines than the equivalent DB-API code...

            Can you tell me more about getCollectionGraph?
            When to use, how to use, what is the effect/meaning of the "{}"?
              • 3749
              • 24,544 Posts
              The {} is json data, but you can also use a PHP array. Here’s all I know about it (an excerpt from my upcoming book):

              getCollectionGraph(string $className, mixed $graph, [mixed $criteria = null],[mixed $cacheFlag = true]) — Like getCollection(), but $graph specifies related objects to retrieve along with the named object (in JSON or PHP array format) in a single query. Returns an array of objects or an empty array on failure. Logs an error if more than one object is found. Sending an empty array for $criteria will get all objects. Set $cacheFlag to false if you don’t need to cache the results.

              Example:
              <?php
              
              /* get all active users and their profiles */
              
              $users = $modx->getCollectionGraph('modUser', array('Profile' =>array()), array('active'=> '1'))'
              
              /* JSON form equivalent to above . . .
              $users = $modx->getObjectGraph('modUser', '{"Profile":{}}', array('active' => '1'));
              */
              
              /* get all users except JoeBlow . . .
              
              $users = $modx->getCollectionGraph('modUser', array('Profile' =>array()), array('username:!='=> 'JoeBlow'))'
              
              */
              
              /* display user data with Tpl chunk */
              
              foreach ($users as $user) {
              
                  $output[] = $modx->getChunk( 'userTpl', array_merge($user->toArray(), $user->Profile->toArray()));
              }
              
              return implode("\n", $output);
              
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 3496
                • 101 Posts
                Hi Bob,
                That makes it much clearer. Now I can also understand the CollectionGraph example in this topic:
                http://modxcms.com/forums/index.php/topic,45663.msg269975.html#msg269975
                Does indeed sound as a useful way to collect data. Thanks!