We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11927
    • 105 Posts
    In Revo 2.0 and then in 2.1 is this the correct way to connect to a different database?

    <?php
    include "my/file/configCustom.inc.php";
    $dbase = ltrim($dbase, "`");
    $dbase = rtrim($dbase, "`");
    $xpdo = new xPDO('mysql:host=local;dbname=myDataBase', $database_user, $database_password, '');
    
    $sql = 'SELECT * FROM `table`';
    $rs = $xpdo->query($sql);
    while($row = $modx->db->getRow($rs))
    {
    /* do whatever I want */
    }



    I’ve seen what Bob did, but wow, way over my head. (And I think too much work for one or two queries.)

    http://bobsguides.com/custom-db-tables.html
      You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

      Carpet Cleaning
      • 3749
      • 24,544 Posts
      You can’t use xPDO without going through the process of creating the schema and the class and map files. If you want to avoid that, you can use PDO.

      http://php.net/manual/en/book.pdo.php
        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
        • 11927
        • 105 Posts
        So, it shouldn’t be working?

        I put it in some code last night in 2.0.7 and it worked fine. Is that bad?


        So instead of the above I would use this? (I’m not trying to hack stuff. I’m trying to learn and start with simple stuff.)
        <?php
        include "my/file/configCustom.inc.php";
        $dbase = ltrim($dbase, "`");
        $dbase = rtrim($dbase, "`");
        $pdo = new PDO('mysql:host=local;dbname=myDataBase', $database_user, $database_password);
        
        $sql = 'SELECT * FROM `table`';
        $rs = $pdo->query($sql);
        while($row = $modx->db->getRow($rs))
        {
        /* do whatever I want */
        }
          You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

          Carpet Cleaning
          • 19388
          • 297 Posts
          You can do something like this:
          $rows= array();
          	$stmt= $modx->query("SELECT * FROM fotosUsuarios");
          	if ($stmt) {
          		$rows = $stmt->fetchAll();
              }
          	print_r($rows);