Page 1 of 1

2 databases kills user defined tag/weird-interesting problem

Posted: Thu Jan 11, 2007 12:36 am
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

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

Posted: Fri Jul 06, 2007 2:19 pm
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

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

Posted: Fri Jul 06, 2007 3:07 pm
by cyberman
I'm not a dev but have you read this?

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

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

Posted: Fri Jul 06, 2007 3:28 pm
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

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

Posted: Fri Jul 06, 2007 3:36 pm
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.

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

Posted: Fri Jul 06, 2007 3:38 pm
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.

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

Posted: Fri Jul 06, 2007 4:59 pm
by Nullig
Try adding:

adodb_connect();

to the end of your UDT

Nullig

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

Posted: Fri Jul 20, 2007 4:24 pm
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

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

Posted: Tue Sep 11, 2007 2:20 pm
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.

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

Posted: Tue Sep 11, 2007 3:06 pm
by calguy1000
Another FAQ issue.... though an advanced topic.