We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Is there a way to print out the database credentials used in a given $modx/$xpdo instance? I mean, they are all defined in the config.inc.php, but it's sorta janky to include the file again just to read those vars. Is there a $xpdo->showCreds() or something?

    Why am I doing this? Because I need to pass some creds to a 3rd party library and it's not practical to rewrite someone else's library.
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: Everettg_99 at Aug 07, 2013, 01:28 PM
      Is there a way to print out the database credentials used in a given $modx/$xpdo instance? I mean, they are all defined in the config.inc.php, but it's sorta janky to include the file again just to read those vars. Is there a $xpdo->showCreds() or something?

      Why am I doing this? Because I need to pass some creds to a 3rd party library and it's not practical to rewrite someone else's library.

      Maybe this?
      $xpdo->getConnection()->getOption('username');
      $xpdo->getConnection()->getOption('password');
      $xpdo->getConnection()->getOption('dsn');
      


      The problem is, you may have multiple connections defined, but if you know there is only one, this should work.
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        Thanks Jason. It used to be that a single $xpdo instance was pegged to a single connection, so in that case it'd be easy enough to just run these methods on the particular variable in question... but if we've got multiple connections inside a single $xpdo instance, is there any way to specify one connection over another?

        Thanks!
          • 22303 MODX Staff
          • 10,725 Posts
          You can specify the kind of connection (i.e. mutable or not), but not a specific one, since this is intended to handle an environment running multiple read-only slaves and only one mutable master.

          $xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true));