accessing another database within c5 using the php block
PermalinkI'm using an form app called MachForm that is also self-hosted php/mysql. It offers a php snippet to include the form on a php page.
When I use one of the PHP blocks on my c5 site to include the code I get errors.
Here they are (obviously not actually php):
mysql error: [1146: Table 'db84663_forms.CollectionVersionBlocks' doesn't exist] in EXECUTE("select Blocks.bID, CollectionVersionBlocks.arHandle from CollectionVersionBlocks inner join Blocks on (CollectionVersionBlocks.bID = Blocks.bID) inner join BlockTypes on (Blocks.btID = BlockTypes.btID) where CollectionVersionBlocks.cID = '95' and (CollectionVersionBlocks.cvID = '27' or CollectionVersionBlocks.cbIncludeAll=1) and CollectionVersionBlocks.arHandle = 'Sub-navigation' order by CollectionVersionBlocks.cbDisplayOrder asc") Fatal error: Uncaught exception 'ADODB_Exception' with message 'mysql error: [1146: Table 'db84663_forms.Logs' doesn't exist] in EXECUTE("insert into Logs (logType, logText, logIsInternal) values ('exceptions', 'Exception Occurred: mysql error: [1146: Table \'db84663_forms.CollectionVersionBlocks\' doesn\'t exist] in EXECUTE("select Blocks.bID, CollectionVersionBlocks.arHandle from CollectionVersionBlocks inner join Blocks on (CollectionVersionBlocks.bID = Blocks.bID) inner join BlockTypes on (Blocks.btID = BlockTypes.btID) where CollectionVersionBlocks.cID = \'95\' and (CollectionVersionBlocks.cvID = \'27\' or CollectionVersionBlocks.cbIncludeAll=1) and CollectionVersionBlocks.arHandle = \'Sub-navigation\' order by CollectionVersionBlocks.cbDisplayOrder asc")\n\n#0 /nfs/c04/h05/mnt/84663/domains/saphireeventgroup.com/html/concrete/libraries/3rdparty/adodb/adodb.inc.php(1042): adodb_throw(\'mysql\', \'EXECUTE\', 1146, \'Table \'db84663_...\', \'select Blocks.b...\', false, Object(ADODB_mysql))\n#1 /nfs/c04/h05/m in /nfs/c04/h05/mnt/84663/domains/saphireeventgroup.com/html/concrete/libraries/3rdparty/adodb/adodb-exceptions.inc.php on line 78
This can be seen at:http://www.saphireeventgroup.com/index.php?cID=95...
It appears that there is a mix-up on which database to access, so an error is generated ("db84663_forms" is the form app database).
Is there a way to make this work? I have the php code for the form app and can make modifications if necessary.
Thank you!

So, instead of using '... from table' make it ' ... from db.table'.
As long as the user/password are the same, this should work.
I know nothing about mysql commands, so I'm not sure how to go about modifying how this other app accesses the second database.
How/where would I go about prepending the db name to the table?
Would it be here? (seems unlikely)
function connect_db(){ $link = mysql_connect(MF_DB_HOST, MF_DB_USER, MF_DB_PASSWORD) or die('Could not connect: ' . mysql_error()); mysql_select_db(MF_DB_NAME) or die('Could not select database'); mysql_query("SET NAMES utf8"); return $link; }
(I prepended the DB variables with "MF_" in hope that would keep them from interfering with c5.)
Or here (for example)? (seems more likely)
$query = "select form_name, form_description, form_redirect, form_success_message, form_password, form_unique_ip, form_frame_height, form_has_css, form_active, form_captcha, form_review from ap_forms where
For now I'm having to use an iframe to keep the two apps from interfering with each other.
Maybe there is a simpler way to shield one app from the other?