2 databases kills user defined tag/weird-interesting problem

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
aravenwood

2 databases kills user defined tag/weird-interesting problem

Post by aravenwood »

Hi I have a weird issue. 

I have a CMS system setup.  In addition, I have a second mysql database setup with some info I want to keep separate from the CMS database.

I have a page that displays data from the second database in a sortable grid.

On the page are a user defined tag and a global content block:

The global content bloc is for a footer at the bottom of every page, and that appears in my template

The user defined tag contains some php code that displays the grid/table.  I noticed that whenever I make explicit mysql calls in this tag's php code, the footer disappears, and there is an CMS error in the source code.


global content bloc's error code:
 
 
      string(61) "Smarty error: unable to read resource: "globalcontent:footer""
string(61) "Smarty error: unable to read resource: "globalcontent:footer""
   
 


global content bloc's code"





Grid tag's php:
//session junk here
session_start();
if(isset($_GET['direction'])){$direction=$_GET['direction'];}else{$direction='asc';}
if(isset($_GET['sort'])){$sort=$_GET['sort'];}else{$sort='lastname';}

if(isset($_SESSION['sort'])){
//read and write session logic here
}


echo'';
echo'';
echo '';
        //header junk here from the database
        echo'';
echo'';
  echo'';
 

@MYSQL_CONNECT("server","user","password");
$sql='';
@mysql_select_db("selected_non_cms_database");
$sql="some sql here";
$result=MYSQL_QUERY($sql);

    while ($row = mysql_fetch_assoc($result)) {
    echo "";
        //some junk here that I pull from the database
    echo "";
    }
    mysql_free_result($result);
    MYSQL_CLOSE();

Can anyone see where I have gone wrong?  Why won't the footer show?  I half suspect that my method of connecting to the mysql database is disabling the connection to the CMS connection to the CMS database, but I have no idea how to fix this if this is the case.  At first I thought this was a session issue, but now I am not sure.
Any help would be appreciated.

Thanks,
Michael
Sonya

Re: 2 databases kills user defined tag/weird-interesting problem

Post by Sonya »

Hello,

I have exact the same problem. After closing connection to the other DB, I connect again to CMS DB:

Code: Select all

	$dbinstance =& ADONewConnection($config['dbms'], 'pear:date:extend:transaction');
	$conn_func = (isset($config['persistent_db_conn']) && $config['persistent_db_conn'] == true) ? 'PConnect' : 'Connect';
	$connect_result = $dbinstance->$conn_func($config['db_hostname'], $config['db_username'], $config['db_password'], $config['db_name']);

It's only the global_content, which cannot be found anymore, ordinary templates can be processed. I was trying to find the difference in $this->smarty before and after connection to other DB. But there is a lot of stuff and I've gave up  :-[

Any idea from the developers? Just to point where to dig.

Thank you,
Sonya
cyberman

Re: 2 databases kills user defined tag/weird-interesting problem

Post by cyberman »

I'm not a dev but have you read this?

http://forum.cmsmadesimple.org/index.ph ... 863.0.html
alby

Re: 2 databases kills user defined tag/weird-interesting problem

Post by alby »

aravenwood wrote: ..............

@MYSQL_CONNECT("server","user","password");
$sql='';
@mysql_select_db("selected_non_cms_database");
$sql="some sql here";
$result=MYSQL_QUERY($sql);

    while ($row = mysql_fetch_assoc($result)) {
    echo "";
        //some junk here that I pull from the database
    echo "";
    }
    mysql_free_result($result);
    MYSQL_CLOSE();
Try with:
$new_link = @MYSQL_CONNECT("server","user","password", true);
$sql='';
@mysql_select_db("selected_non_cms_database", $new_link);
$sql="some sql here";
$result=MYSQL_QUERY($sql, $new_link);

from php.net:
resource mysql_connect ( [string $server [, string $username [, string $password [, bool $new_link ...)

new_link
    If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters. In SQL safe mode, this parameter is ignored.
Alby

EDIT:  MYSQL_CLOSE($new_link); also
Last edited by alby on Fri Jul 06, 2007 3:36 pm, edited 1 time in total.
Sonya

Re: 2 databases kills user defined tag/weird-interesting problem

Post by Sonya »

cyberman wrote: I'm not a dev but have you read this?
Yes, but there are no issues with global_content. I am able to establish the connection twice and everything works in CMSMS as it should but no global content can be shown. Hmmm... Curious.
Sonya

Re: 2 databases kills user defined tag/weird-interesting problem

Post by Sonya »

Hello Alby,
alby wrote: new_link
    If a second call is made to mysql_connect() with the same arguments,
I have different arguments. It's an other database, so new link has to be forced.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: 2 databases kills user defined tag/weird-interesting problem

Post by Nullig »

Try adding:

adodb_connect();

to the end of your UDT

Nullig
Sonya

Re: 2 databases kills user defined tag/weird-interesting problem

Post by Sonya »

Hello,

thank you for your help. I was not able to solve this problem so far. But I used debug_backtrace() to find out where the problem lies. So I placed debug into /lib/adodb_lite/generic_modules/pear_module.inc in line 2 and got this before using the second database.

Code: Select all

   [1] => Array
        (
            [file] => xxxmyroot\lib\adodb.functions.php
            [line] => 56
            [function] => ADONewConnection
            [args] => Array
                (
                    [0] => mysql
                    [1] => pear:date:extend:transaction
                )

        )
Then I compared the output after using second connection and there war a difference:

Code: Select all

   [1] => Array
        (
            [file] => xxxmyroot\lib\adodb.functions.php
            [line] => 56
            [function] => ADONewConnection
            [args] => Array
                (
                    [0] => 
                    [1] => pear:date:extend:transaction
                )

        )
First argument is missing, so pear sucks.

There are some changes made with pear date according to config:

#Use ADODB Lite?  This should be true in almost all cases.  Note, slight
#tweaks might have to be made to date handling in a "regular" adodb
#install before it can be used.

I do not know if it depends on these changes.

Sonya
Last edited by Sonya on Fri Jul 20, 2007 4:26 pm, edited 1 time in total.
manurevah
Forum Members
Forum Members
Posts: 37
Joined: Fri Aug 03, 2007 2:24 pm

Re: 2 databases kills user defined tag/weird-interesting problem

Post by manurevah »

Nullig wrote: Try adding:

adodb_connect();

to the end of your UDT

Nullig

\o/  sorry to interrupt, but i googled and got lucky because your tip works swell for me..  thanks.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: 2 databases kills user defined tag/weird-interesting problem

Post by calguy1000 »

Another FAQ issue.... though an advanced topic.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Locked

Return to “CMSMS Core”