We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20865
    • 30 Posts
    Hello everyone.
    I need to get some data from anouther DB but var_dump returns NULL. There are a topic but nobody replyed on it.
    Please help
    <?php
    $connect = MYSQL_CONNECT('arguments');
    $selection = mysql_select_db('db name', $connect);
    if(!$void)
    {
      echo "Died";
    }
    else
    {
      $stmt = mysql_query("SELECT * FROM tablename", $selection);
      $ikd = mysql_fetch_row($stmt);
      var_dump($ikd);
    }
    ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
      • 20865
      • 30 Posts
      so nobody knows the answer? huh
      How you are living without selecting anouther DB?
      Will this work ? There are nothing about those DBAPI functions.
      $conecting = $modx->db->connect($host='localhost', $dbase = 'basename', $uid = 'username', $pwd = 'password');
      $modx->db->exec(mysql_select_db('dbname', $connecting));
      $modx->db->select($from='tablename');
      

      Will try it a bit later.
        • 18913
        • 654 Posts
        Hi,
        I’ve done this. For example try something like this in a snippet :
        //try to connect to and select the database 
        mysql_connect(DATABASEHOST,DATABASEUSERNAME,DATABASEPASSWORD) OR DIE ('Unable to connect to database! Please try again later.');
        mysql_select_db(DATABASENAME) or die( "Unable to select database");
        $query = 'YOUR SQL QUERY GOES HERE';
        $rs = mysql_query($query);
        mysql_close();
        
        if ($rs)
        {
        	while( $row = mysql_fetch_assoc($rs) )
        	{
        		//YOUR MANIPULATION OF THE DATA GOES HERE
        	}
        }
        


        (adapted from this thread http://modxcms.com/forums/index.php/topic,14654.msg332937.html#msg332937)
        Matt

        EDIT : That thread is for Evolution.
          • 20865
          • 30 Posts
          Thanks for reply.
          There was a mistake
          must be
          $stmt = mysql_query("SELECT * FROM tablename", $connect);

          instead of
          $stmt = mysql_query("SELECT * FROM tablename", $selection);

          PS weird that i have left this uncheked...
          PSS I think there are no difference beetween Evo and Revo DBAPI and MySQL functions )